Java Code Examples for com.fasterxml.jackson.core.JsonParser

The following examples show how to use com.fasterxml.jackson.core.JsonParser. These examples are extracted from open source projects. 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
@Override
public CloudError deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    p.setCodec(mapper);
    JsonNode errorNode = p.readValueAsTree();

    if (errorNode == null) {
        return null;
    }
    if (errorNode.get("error") != null) {
        errorNode = errorNode.get("error");
    }
    
    JsonParser parser = new JsonFactory().createParser(errorNode.toString());
    parser.setCodec(mapper);
    return parser.readValueAs(CloudError.class);
}
 
Example 2
Source Project: jigsaw-payment   Source File: JsonJacksonFormat.java    License: Apache License 2.0 6 votes vote down vote up
private void handleValue(JsonParser parser,
                                ExtensionRegistry extensionRegistry,
                                Message.Builder builder,
                                FieldDescriptor field,
                                ExtensionRegistry.ExtensionInfo extension,
                                boolean unknown) throws IOException {

    Object value = null;
    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        value = handleObject(parser, extensionRegistry, builder, field, extension, unknown);
    } else {
        value = handlePrimitive(parser, field);
    }
    if (value != null) {
        if (field.isRepeated()) {
            builder.addRepeatedField(field, value);
        } else {
            builder.setField(field, value);
        }
    }
}
 
Example 3
Source Project: ltr4l   Source File: FeaturesExtractorManager.java    License: Apache License 2.0 6 votes vote down vote up
public SimpleOrderedMap<Object> getResult(){
  if(future.isDone()){
    SimpleOrderedMap<Object> result = new SimpleOrderedMap<Object>();
    Reader r = null;
    try{
      r = new FileReader(featuresFile);
      ObjectMapper mapper = new ObjectMapper();
      mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
      Map<String, Object> json = mapper.readValue(featuresFile, Map.class);
      result.add("data", parseData(json));
      return result;
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally{
      IOUtils.closeWhileHandlingException(r);
    }
  }
  else return null;
}
 
Example 4
Source Project: olingo-odata4   Source File: ClientCsdlReference.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected ClientCsdlReference doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {
  final ClientCsdlReference reference = new ClientCsdlReference();

  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Uri".equals(jp.getCurrentName())) {
        reference.setUri(URI.create(jp.nextTextValue()));
      } else if ("Include".equals(jp.getCurrentName())) {
        jp.nextToken();
        reference.getIncludes().add(jp.readValueAs( ClientCsdlInclude.class));
      } else if ("IncludeAnnotations".equals(jp.getCurrentName())) {
        jp.nextToken();
        reference.getIncludeAnnotations().add(jp.readValueAs( ClientCsdlIncludeAnnotations.class));
      } else if ("Annotation".equals(jp.getCurrentName())) {
        jp.nextToken();
        reference.getAnnotations().add(jp.readValueAs( ClientCsdlAnnotation.class));
      }
    }
  }

  return reference;
}
 
Example 5
Source Project: odata   Source File: JsonProcessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Initialize processor, automatically scanning the input JSON.
 * @throws ODataUnmarshallingException If unable to initialize
 */
public void initialize() throws ODataUnmarshallingException {
    LOG.info("Parser is initializing");
    try {
        JsonParser jsonParser = JSON_FACTORY.createParser(inputJson);

        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String token = jsonParser.getCurrentName();
            if (token != null) {
                if (token.startsWith(ODATA)) {
                    processSpecialTags(jsonParser);
                } else if (token.endsWith(ODATA_BIND)) {
                    processLinks(jsonParser);
                } else {
                    process(jsonParser);
                }
            }
        }
    } catch (IOException e) {
        throw new ODataUnmarshallingException("It is unable to unmarshall", e);
    }
}
 
Example 6
Source Project: apiman   Source File: HeaderMapDeserializer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
 */
@Override
public HeaderMap deserialize(JsonParser p, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    HeaderMap map = new HeaderMap();

    while (p.nextToken() != JsonToken.END_OBJECT) {
        String name = p.getCurrentName();

        p.nextToken();

        if (p.currentToken().isScalarValue()) {
            map.add(name, p.getValueAsString());
        } else {
            ArrayDeque<String> values = new ArrayDeque<>();
            while (p.nextToken() != JsonToken.END_ARRAY) {
                values.push(p.getValueAsString());
            }
            values.forEach(value -> map.add(name, value));
        }
    }
    return map;
}
 
Example 7
Source Project: signal-cli   Source File: JsonPreKeyStore.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public JsonPreKeyStore deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);

    Map<Integer, byte[]> preKeyMap = new HashMap<>();
    if (node.isArray()) {
        for (JsonNode preKey : node) {
            Integer preKeyId = preKey.get("id").asInt();
            try {
                preKeyMap.put(preKeyId, Base64.decode(preKey.get("record").asText()));
            } catch (IOException e) {
                System.out.println(String.format("Error while decoding prekey for: %s", preKeyId));
            }
        }
    }

    JsonPreKeyStore keyStore = new JsonPreKeyStore();
    keyStore.addPreKeys(preKeyMap);

    return keyStore;

}
 
Example 8
Source Project: botbuilder-java   Source File: CloudErrorDeserializer.java    License: MIT License 6 votes vote down vote up
@Override
public CloudError deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    p.setCodec(mapper);
    JsonNode errorNode = p.readValueAsTree();

    if (errorNode == null) {
        return null;
    }
    if (errorNode.get("error") != null) {
        errorNode = errorNode.get("error");
    }

    JsonParser parser = new JsonFactory().createParser(errorNode.toString());
    parser.setCodec(mapper);
    return parser.readValueAs(CloudError.class);
}
 
Example 9
Source Project: fahrschein   Source File: PropertyExtractingEventReader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<T> read(JsonParser jsonParser) throws IOException {
    expectToken(jsonParser.nextToken(), JsonToken.START_ARRAY);

    final List<T> result = new ArrayList<>();

    for (JsonToken token = jsonParser.nextToken(); token != JsonToken.END_ARRAY; token = jsonParser.nextToken()) {
        expectToken(token, JsonToken.START_OBJECT);

        for (token = jsonParser.nextToken(); token != JsonToken.END_OBJECT; token = jsonParser.nextToken()) {
            expectToken(token, JsonToken.FIELD_NAME);

            final String topLevelProperty = jsonParser.getCurrentName();
            jsonParser.nextToken();

            if (propertyName.equals(topLevelProperty)) {
                final T value = getValue(jsonParser);
                result.add(value);
            } else {
                jsonParser.skipChildren();
            }
        }
    }

    return result;
}
 
Example 10
Source Project: divolte-collector   Source File: AvroGenericRecordMapper.java    License: Apache License 2.0 6 votes vote down vote up
private List<?> readArray(final JsonParser parser,
                          final Schema targetSchema) throws IOException {
    Preconditions.checkArgument(targetSchema.getType() == Schema.Type.ARRAY);
    final List<?> result;
    final Schema elementType = targetSchema.getElementType();
    if (parser.isExpectedStartArrayToken()) {
        final List<Object> builder = new ArrayList<>();
        while (JsonToken.END_ARRAY != parser.nextToken()) {
            builder.add(read(parser, elementType));
        }
        result = builder;
    } else if (reader.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
        result = Collections.singletonList(read(parser, elementType));
    } else {
        throw mappingException(parser, targetSchema);
    }
    return result;
}
 
Example 11
@Override protected void read(NativeRequestExt.Builder ext, JsonParser par) throws IOException {
  switch (getCurrentName(par)) {
    case "style_id":
      ext.setStyleId(par.nextIntValue(0));
      break;
    case "style_height":
      ext.setStyleHeight(par.nextIntValue(0));
      break;
    case "style_width":
      ext.setStyleWidth(par.nextIntValue(0));
      break;
    case "style_layout_type": {
        LayoutType value = LayoutType.forNumber(par.nextIntValue(0));
        if (checkEnum(value)) {
          ext.setStyleLayoutType(value);
        }
      }
      break;
  }
}
 
Example 12
Source Project: synapse   Source File: SnapshotParser.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> void processSnapshotData(final JsonParser parser,
                                     final ChannelPosition channelPosition,
                                     final MessageDispatcher messageDispatcher) throws IOException {
    final Decoder<SnapshotMessage> decoder = new SnapshotMessageDecoder();
    final ShardPosition shardPosition = channelPosition.shard(channelPosition.shards().iterator().next());
    while (parser.nextToken() != JsonToken.END_ARRAY) {
        JsonToken currentToken = parser.currentToken();
        if (currentToken == JsonToken.FIELD_NAME) {
            final TextMessage message = decoder.apply(new SnapshotMessage(
                    Key.of(parser.getValueAsString()),
                    Header.of(shardPosition),
                    parser.nextTextValue()));
            messageDispatcher.accept(message);
        }
    }
}
 
Example 13
Source Project: web3j-quorum   Source File: PermissionNodeList.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<PermissionNodeInfo> deserialize(
        JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {
    List<PermissionNodeInfo> nodeList = new ArrayList<>();
    JsonToken nextToken = jsonParser.nextToken();

    if (nextToken == JsonToken.START_OBJECT) {
        Iterator<PermissionNodeInfo> nodeInfoIterator =
                om.readValues(jsonParser, PermissionNodeInfo.class);
        while (nodeInfoIterator.hasNext()) {
            nodeList.add(nodeInfoIterator.next());
        }
        return nodeList;
    } else {
        return null;
    }
}
 
Example 14
Object deserialize(JsonNode node, String fieldName, Class targetClass, DeserializationContext ctxt) throws IOException {
    final String type = getFieldClassFQN(targetClass, valueType);
    try {
        // load class of the field
        final Class<?> fieldClass = Thread.currentThread().getContextClassLoader().loadClass(type);
        // create a map type matching the type of the field from the mapping information
        final YAMLMapper codec = (YAMLMapper) ctxt.getParser().getCodec();
        MapType mapType = codec.getTypeFactory().constructMapType(Map.class, String.class, fieldClass);
        // get a parser taking the current value as root
        final JsonParser traverse = node.get(fieldName).traverse(codec);
        // and use it to deserialize the subtree as the map type we just created
        return codec.readValue(traverse, mapType);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Unsupported type '" + type + "' for field '" + fieldName +
                "' on '" + targetClass.getName() + "' class. Full type was " + this, e);
    }
}
 
Example 15
Source Project: querqy   Source File: PropertiesBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public PropertiesBuilder() {
    objectMapper = new ObjectMapper();
    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    objectMapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true);
    objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
    objectMapper.configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS, true);
    objectMapper.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true);



    jsonPathConfiguration = Configuration.builder()
            .jsonProvider(new JacksonJsonProvider())
            .mappingProvider(new JacksonMappingProvider()).build();
    jsonPathConfiguration.addOptions(Option.ALWAYS_RETURN_LIST);

    primitiveProperties = new HashMap<>();
    jsonObjectString =  new StringBuilder();

}
 
Example 16
Source Project: JsonSurfer   Source File: JacksonParser.java    License: MIT License 5 votes vote down vote up
JacksonResumableParser(final JsonParser jsonParser, SurfingContext context) {
    this.jsonParser = jsonParser;
    this.context = context;
    final JsonProvider jsonProvider = context.getConfig().getJsonProvider();
    this.stringHolder = new AbstractPrimitiveHolder(context.getConfig()) {
        @Override
        public Object doGetValue() throws IOException {
            return jsonProvider.primitive(jsonParser.getText());
        }

        @Override
        public void doSkipValue() throws IOException {
        }
    };
    this.longHolder = new AbstractPrimitiveHolder(context.getConfig()) {
        @Override
        public Object doGetValue() throws IOException {
            return jsonProvider.primitive(jsonParser.getLongValue());
        }

        @Override
        public void doSkipValue() throws IOException {
        }
    };
    this.doubleHolder = new AbstractPrimitiveHolder(context.getConfig()) {
        @Override
        public Object doGetValue() throws IOException {
            return jsonProvider.primitive(jsonParser.getDoubleValue());
        }

        @Override
        public void doSkipValue() throws IOException {
        }
    };
    this.staticHolder = new StaticPrimitiveHolder();
}
 
Example 17
Source Project: kripton   Source File: LongBeanTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * for attribute value parsing
 */
public static long[] parseValue(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();
    long[] result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      ArrayList<Long> collection=new ArrayList<>();
      Long item=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
          item=null;
        } else {
          item=jacksonParser.getLongValue();
        }
        collection.add(item);
      }
      result=CollectionUtils.asLongTypeArray(collection);
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 18
Source Project: streams   Source File: StreamsJacksonMapper.java    License: Apache License 2.0 5 votes vote down vote up
public void configure() {
  disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
  configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, Boolean.TRUE);
  configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
  configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);
  configure(DeserializationFeature.WRAP_EXCEPTIONS, Boolean.FALSE);
  configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, Boolean.TRUE);
  // If a user has an 'object' that does not have an explicit mapping, don't cause the serialization to fail.
  configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, Boolean.FALSE);
  configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, Boolean.FALSE);
  configure(SerializationFeature.WRITE_NULL_MAP_VALUES, Boolean.FALSE);
  setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.DEFAULT);
  setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
}
 
Example 19
Source Project: kripton   Source File: Bean64Table.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueCharList parsing
 */
public static LinkedList<Character> parseValueCharList(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();
    LinkedList<Character> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      LinkedList<Character> collection=new LinkedList<>();
      Character item=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
          item=null;
        } else {
          item=Character.valueOf((char)jacksonParser.getIntValue());
        }
        collection.add(item);
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 20
Source Project: kripton   Source File: AlbumBindMap.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Album parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Album instance = new Album();
  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 "artistId":
          // field artistId (mapped with "artistId")
          instance.artistId=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.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 21
Source Project: kripton   Source File: BeanTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueByteSet parsing
 */
public static Set<Byte> parseValueByteSet(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();
    Set<Byte> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      HashSet<Byte> collection=new HashSet<>();
      Byte item=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
          item=null;
        } else {
          item=jacksonParser.getByteValue();
        }
        collection.add(item);
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 22
Source Project: openrtb-doubleclick   Source File: AppExtReader.java    License: Apache License 2.0 5 votes vote down vote up
protected void readInstalledSdkField(JsonParser par, InstalledSdk.Builder sdk, String fieldName)
    throws IOException {
  switch (fieldName) {
    case "id":
      sdk.setId(par.getText());
      break;
    case "sdk_version":
      sdk.setSdkVersion(readVersion(par));
      break;
    case "adapter_version":
      sdk.setAdapterVersion(readVersion(par));
      break;
  }
}
 
Example 23
Source Project: web3j-quorum   Source File: IstanbulBlockSigners.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BlockSigners deserialize(
        JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {
    if (jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) {
        return objectReader.readValue(jsonParser, BlockSigners.class);
    } else {
        return null; // null is wrapped by Optional in above getter
    }
}
 
Example 24
Source Project: kripton   Source File: Bean64Table.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueBeanArray parsing
 */
public static Bean64[] parseValueBeanArray(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();
    Bean64[] result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      ArrayList<Bean64> collection=new ArrayList<>();
      Bean64 item=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
          item=null;
        } else {
          item=bean64BindMap.parseOnJackson(jacksonParser);
        }
        collection.add(item);
      }
      result=CollectionUtils.asArray(collection, new Bean64[collection.size()]);
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 25
Source Project: tutorials   Source File: CustomDateDeserializer.java    License: MIT License 5 votes vote down vote up
@Override
public Date deserialize(JsonParser jsonparser, DeserializationContext context) throws IOException {
    String date = jsonparser.getText();
    try {
        return formatter.parse(date);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
 
Example 26
Source Project: syndesis   Source File: JsonRecordSupport.java    License: Apache License 2.0 5 votes vote down vote up
public static void jsonStreamToRecords(Set<String> indexes, String dbPath, InputStream is, Consumer<JsonRecord> consumer) throws IOException {
    try (JsonParser jp = new JsonFactory().createParser(is)) {
        jsonStreamToRecords(indexes, jp, dbPath, consumer);

        JsonToken jsonToken = jp.nextToken();
        if (jsonToken != null) {
            throw new JsonParseException(jp, "Document did not terminate as expected.");
        }
    }
}
 
Example 27
Source Project: kripton   Source File: BeanTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * for attribute valueBeanSet parsing
 */
public static LinkedHashSet<Bean> parseValueBeanSet(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();
    LinkedHashSet<Bean> result=null;
    if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
      LinkedHashSet<Bean> collection=new LinkedHashSet<>();
      Bean item=null;
      while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
        if (jacksonParser.currentToken()==JsonToken.VALUE_NULL) {
          item=null;
        } else {
          item=beanBindMap.parseOnJackson(jacksonParser);
        }
        collection.add(item);
      }
      result=collection;
    }
    return result;
  } catch(Exception e) {
    e.printStackTrace();
    throw(new KriptonRuntimeException(e.getMessage()));
  }
}
 
Example 28
Source Project: flow-platform-x   Source File: JsonablePage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Pageable deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    JsonNode node = p.getCodec().readTree(p);
    int pageNumber = node.get("pageNumber").asInt();
    int pageSize = node.get("pageSize").asInt();
    return PageRequest.of(pageNumber, pageSize);
}
 
Example 29
private void readAndWrite(final InputStream input, final OutputStream output) throws IOException {
  try (JsonParser parser = new CurrentPathJsonParser(_jsonFactory.createParser(input))) {

    JsonToken token = _initForReading(parser, valueType);
    DeserializationConfig config = getDeserializationConfig();
    DeserializationContext context = createDeserializationContext(parser, config);

    if (token != VALUE_NULL && token != END_ARRAY && token != END_OBJECT) {

      try (JsonGenerator generator = jsonFactory.createGenerator(output)) {

        generator.writeStartObject();

        beforeDeserialize(generator);

        JsonDeserializer<?> rootDeserializer = _findRootDeserializer(context, valueType);
        deserializeAndSerialize(parser, context, (MapDeserializer) rootDeserializer, generator);

        afterDeserialize(generator);

        context.checkUnresolvedObjectId();
      }
    }

    if (config.isEnabled(FAIL_ON_TRAILING_TOKENS)) {
      _verifyNoTrailingTokens(parser, context, valueType);
    }
  }
}
 
Example 30
Source Project: phoebus   Source File: JsonModelReader.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** Parse JSON text
 *  @param json_text JSON text
 *  @return JSON object
 *  @throws Exception
 */
public static Object parseJsonText(final String json_text) throws Exception
{
    try
    (
        final JsonParser jp = JsonModelWriter.mapper.getFactory().createParser(json_text);
    )
    {
        return JsonModelWriter.mapper.readTree(jp);
    }
}