Java Code Examples for com.fasterxml.jackson.core.JsonToken#START_OBJECT

The following examples show how to use com.fasterxml.jackson.core.JsonToken#START_OBJECT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositeReader.java    From vespa with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "cast", "rawtypes" })
public static void populateComposite(TokenBuffer buffer, FieldValue fieldValue) {
    JsonToken token = buffer.currentToken();
    if ((token != JsonToken.START_OBJECT) && (token != JsonToken.START_ARRAY)) {
        throw new IllegalArgumentException("Expected '[' or '{'. Got '" + token + "'.");
    }
    if (fieldValue instanceof CollectionFieldValue) {
        DataType valueType = ((CollectionFieldValue) fieldValue).getDataType().getNestedType();
        if (fieldValue instanceof WeightedSet) {
            fillWeightedSet(buffer, valueType, (WeightedSet) fieldValue);
        } else {
            fillArray(buffer, (CollectionFieldValue) fieldValue, valueType);
        }
    } else if (fieldValue instanceof MapFieldValue) {
        MapReader.fillMap(buffer, (MapFieldValue) fieldValue);
    } else if (fieldValue instanceof StructuredFieldValue) {
        StructReader.fillStruct(buffer, (StructuredFieldValue) fieldValue);
    } else if (fieldValue instanceof TensorFieldValue) {
        TensorReader.fillTensor(buffer, (TensorFieldValue) fieldValue);
    } else {
        throw new IllegalArgumentException("Expected a " + fieldValue.getClass().getName() + " but got an " +
                                           (token == JsonToken.START_OBJECT ? "object" : "array" ));
    }
    expectCompositeEnd(buffer.currentToken());
}
 
Example 2
Source File: PlatonBlock.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Override
public List<TransactionResult> deserialize(
        JsonParser jsonParser,
        DeserializationContext deserializationContext) throws IOException {

    List<TransactionResult> transactionResults = new ArrayList<>();
    JsonToken nextToken = jsonParser.nextToken();

    if (nextToken == JsonToken.START_OBJECT) {
        Iterator<TransactionObject> transactionObjectIterator =
                objectReader.readValues(jsonParser, TransactionObject.class);
        while (transactionObjectIterator.hasNext()) {
            transactionResults.add(transactionObjectIterator.next());
        }
    } else if (nextToken == JsonToken.VALUE_STRING) {
        jsonParser.getValueAsString();

        Iterator<TransactionHash> transactionHashIterator =
                objectReader.readValues(jsonParser, TransactionHash.class);
        while (transactionHashIterator.hasNext()) {
            transactionResults.add(transactionHashIterator.next());
        }
    }

    return transactionResults;
}
 
Example 3
Source File: FriendBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Friend parseOnJackson(JsonParser jacksonParser) throws Exception {
  Friend instance = new Friend();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getIntValue();
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 4
Source File: PetBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Pet parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Pet instance = new Pet();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        case "userId":
          // field userId (mapped with "userId")
          instance.userId=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 5
Source File: BeanTable.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueLinkedMapStringBean parsing
 */
public static LinkedHashMap<String, Bean> parseValueLinkedMapStringBean(byte[] input) {
  if (input==null) {
    return null;
  }
  KriptonJsonContext context=KriptonBinder.jsonBind();
  try (JacksonWrapperParser wrapper=context.createParser(input)) {
    JsonParser jacksonParser=wrapper.jacksonParser;
    // START_OBJECT
    jacksonParser.nextToken();
    // value of "element"
    jacksonParser.nextValue();
    LinkedHashMap<String, Bean> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      LinkedHashMap<String, Bean> collection=new LinkedHashMap<>();
      String key=null;
      Bean value=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        jacksonParser.nextValue();
        key=jacksonParser.getText();
        jacksonParser.nextValue();
        if (jacksonParser.currentToken()==JsonToken.START_OBJECT) {
          value=beanBindMap.parseOnJackson(jacksonParser);
        }
        collection.put(key, value);
        key=null;
        value=null;
        jacksonParser.nextToken();
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 6
Source File: JsonPropertyWriterTest.java    From odata with Apache License 2.0 5 votes vote down vote up
private List<Object> getJsonArray(JsonParser jsonParser) throws IOException {
    List<Object> objects = new ArrayList<>();
    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
            Map<String, String> jsonObject = getJsonObject(jsonParser);
            objects.add(jsonObject);
        } else {
            objects.add(jsonParser.getText());
        }
    }
    return objects;
}
 
Example 7
Source File: PersonBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Person parseOnJackson(JsonParser jacksonParser) throws Exception {
  Person instance = new Person();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "age":
          // field age (mapped with "age")
          instance.age=jacksonParser.getIntValue();
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 8
Source File: HollowJsonAdapter.java    From hollow with Apache License 2.0 5 votes vote down vote up
private int parseSubType(JsonParser parser, FlatRecordWriter flatRecordWriter, JsonToken currentToken, String subType) throws IOException {
    HollowSchema subTypeSchema = hollowSchemas.get(subType);
    switch(subTypeSchema.getSchemaType()) {
        case OBJECT:
            if(currentToken != JsonToken.START_OBJECT)
                throw new IOException("Expecting to parse a " + subType + ", which is a " + subTypeSchema.getSchemaType() + ", expected JsonToken.START_OBJECT but instead found a " + currentToken.toString());

            return addObject(parser, flatRecordWriter, subType);

        case LIST:
        case SET:
            if(currentToken != JsonToken.START_ARRAY)
                throw new IOException("Expecting to parse a " + subType + ", which is a " + subTypeSchema.getSchemaType() + ", expected JsonToken.START_ARRAY but instead found a " + currentToken.toString());

            return addSubArray(parser, flatRecordWriter, subType, getWriteRecord(subType));

        case MAP:
            switch(currentToken) {
                case START_ARRAY:
                    return addStructuredMap(parser, flatRecordWriter, subType, (HollowMapWriteRecord) getWriteRecord(subType));
                case START_OBJECT:
                    return addUnstructuredMap(parser, flatRecordWriter, subType, (HollowMapWriteRecord) getWriteRecord(subType));
                default:
                    throw new IOException("Expecting to parse a " + subType + ", which is a " + subTypeSchema.getSchemaType() + ", expected JsonToken.START_ARRAY or JsonToken.START_OBJECT but instead found a " + currentToken.toString());
            }
    }
    throw new IOException();
}
 
Example 9
Source File: CollegeStudentBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public CollegeStudent parseOnJackson(JsonParser jacksonParser) throws Exception {
  CollegeStudent instance = new CollegeStudent();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "firstName":
          // field firstName (mapped with "firstName")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.firstName=jacksonParser.getText();
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "surname":
          // field surname (mapped with "surname")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.surname=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 10
Source File: Bean02BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean02 parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Bean02 instance = new Bean02();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.setId(PrimitiveUtils.readLong(jacksonParser.getText(), 0L));
        break;
        case "text":
          // field text (mapped with "text")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setText(jacksonParser.getText());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 11
Source File: DocumentBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Document parseOnJackson(JsonParser jacksonParser) throws Exception {
  Document instance = new Document();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "fileName":
          // field fileName (mapped with "fileName")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.fileName=jacksonParser.getText();
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 12
Source File: BeanA_2BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public BeanA_2 parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  BeanA_2 instance = new BeanA_2();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "valueString2":
          // field valueString2 (mapped with "valueString2")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueString2=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 13
Source File: Point3BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Point3 parseOnJackson(JsonParser jacksonParser) throws Exception {
  Point3 instance = new Point3();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "x":
          // field x (mapped with "x")
          instance.x=jacksonParser.getFloatValue();
        break;
        case "y":
          // field y (mapped with "y")
          instance.y=jacksonParser.getFloatValue();
        break;
        case "z":
          // field z (mapped with "z")
          instance.z=jacksonParser.getFloatValue();
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 14
Source File: Bean02BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean02 parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean02 instance = new Bean02();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.setId(jacksonParser.getLongValue());
        break;
        case "text":
          // field text (mapped with "text")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setText(jacksonParser.getText());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 15
Source File: UserIdentityBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public UserIdentity parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  UserIdentity instance = new UserIdentity();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "email":
          // field email (mapped with "email")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setEmail(jacksonParser.getText());
          }
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setName(jacksonParser.getText());
          }
        break;
        case "username":
          // field username (mapped with "username")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setUsername(jacksonParser.getText());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 16
Source File: Bean87A_3BindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean87A_3 parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean87A_3 instance = new Bean87A_3();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "attributeBoolean":
          // field attributeBoolean (mapped with "attributeBoolean")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            // using type adapter bind.feature.typeadapter.kripton87.BooleanByteArrayTypeAdapter
            instance.attributeBoolean=TypeAdapterUtils.toJava(BooleanByteArrayTypeAdapter.class, jacksonParser.getLongValue());
          }
        break;
        case "elementBoolean":
          // field elementBoolean (mapped with "elementBoolean")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            // using type adapter bind.feature.typeadapter.kripton87.BooleanByteArrayTypeAdapter
            instance.elementBoolean=TypeAdapterUtils.toJava(BooleanByteArrayTypeAdapter.class, jacksonParser.getLongValue());
          }
        break;
        case "elementEnum":
          // field elementEnum (mapped with "elementEnum")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            // using type adapter bind.feature.typeadapter.kripton87.Enum87IntegerTypeAdapter
            instance.elementEnum=TypeAdapterUtils.toJava(Enum87IntegerTypeAdapter.class, jacksonParser.getIntValue());
          }
        break;
        case "dataBoolean":
          // field dataBoolean (mapped with "dataBoolean")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            // using type adapter bind.feature.typeadapter.kripton87.BooleanByteArrayTypeAdapter
            instance.dataBoolean=TypeAdapterUtils.toJava(BooleanByteArrayTypeAdapter.class, jacksonParser.getLongValue());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 17
Source File: PersonBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Person parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Person instance = new Person();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "birthCity":
          // field birthCity (mapped with "birthCity")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.birthCity=jacksonParser.getText();
          }
        break;
        case "birthDay":
          // field birthDay (mapped with "birthDay")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.birthDay=DateUtils.read(jacksonParser.getText());
          }
        break;
        case "city":
          // field city (mapped with "city")
          instance.city=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setName(jacksonParser.getText());
          }
        break;
        case "parentId":
          // field parentId (mapped with "parentId")
          instance.parentId=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "surname":
          // field surname (mapped with "surname")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setSurname(jacksonParser.getText());
          }
        break;
        case "value":
          // field value (mapped with "value")
          instance.value=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 18
Source File: JSonDatabaseReader.java    From dbsync with Apache License 2.0 4 votes vote down vote up
void handle(final Map<String, ValueMetadata> colMetadataMap) throws IOException {
    String fieldName;
    ValueMetadata columnMetadata;
    JSonConverter converter;
    Value value;

    // Create a new record
    mCurrentRecord = new Record();
    while (mJp.nextToken() != JsonToken.END_OBJECT) {


        if (mJp.getCurrentToken() == JsonToken.FIELD_NAME) {
            fieldName = mJp.getCurrentName();

            // Get column metadata
            if (!colMetadataMap.containsKey(fieldName)){
                throw new IOException("Unable to find columns metadata for columns " + fieldName);
            }

            columnMetadata = colMetadataMap.get(fieldName);

            // Build the data converter and convert
            converter = JSonConverterFactory.buildConverter(columnMetadata);
            value = converter.jsonToColumnValue(mJp, columnMetadata);

            mCurrentRecord.add(value);
        }
        if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
            // End Array also no records
            break;
        }

    }

    // Go to next token, only if not the end of records
    if (mJp.getCurrentToken() != JsonToken.END_ARRAY) {
        mJp.nextToken();
    }

    if (mJp.getCurrentToken() == JsonToken.START_OBJECT) {
        // The current token is start of object -> new record no change state required
        return;
    } else if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
        // The current token is end of array -> end of record, end of table, end of database

        // Consume end of object of current table
        mJp.nextToken();
        if(mJp.getCurrentToken() != JsonToken.END_OBJECT){
            throw new IOException("Unable to read end of table expected end of object line :" + mJp.getCurrentLocation().getLineNr());
        }

        // Consume other token to dete end of database
        // if START_OBJECT -> new TableToSync
        // if END_ARRAY -> end of database
        mJp.nextToken();
        if (mJp.getCurrentToken() == JsonToken.START_OBJECT) {
            mState = new StartTableState();
        } else if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
            mState = new EndState();
        } else {
            throw new IOException("Unable to read start of table expected { or ] line:" + mJp.getCurrentLocation().getLineNr());
        }
    } else {
        throw new IOException("Unexpected token " + mJp.getCurrentToken() + " line:" + mJp.getCurrentLocation().getLineNr());
    }
}
 
Example 19
Source File: AddressBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Address parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Address instance = new Address();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "city":
          // field city (mapped with "city")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.city=jacksonParser.getText();
          }
        break;
        case "geo":
          // field geo (mapped with "geo")
          if (jacksonParser.currentToken()==JsonToken.START_OBJECT || jacksonParser.currentToken()==JsonToken.VALUE_STRING) {
            instance.geo=geoBindMap.parseOnJacksonAsString(jacksonParser);
          }
        break;
        case "street":
          // field street (mapped with "street")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.street=jacksonParser.getText();
          }
        break;
        case "suite":
          // field suite (mapped with "suite")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.suite=jacksonParser.getText();
          }
        break;
        case "zipcode":
          // field zipcode (mapped with "zipcode")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.zipcode=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 20
Source File: PersonBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Person parseOnJackson(JsonParser jacksonParser) throws Exception {
  Person instance = new Person();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "birthday":
          // field birthday (mapped with "birthday")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.birthday=DateUtils.read(jacksonParser.getText());
          }
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        case "surname":
          // field surname (mapped with "surname")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.surname=jacksonParser.getText();
          }
        break;
        case "tags":
          // field tags (mapped with "tags")
          if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
            ArrayList<String> collection=new ArrayList<>();
            String item=null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
              if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
                item=null;
              } else {
                item=jacksonParser.getText();
              }
              collection.add(item);
            }
            instance.tags=collection;
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}