Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectReader


        return res;
    }

    @Override
    public <T> T deSer(String json, Class<T> type) throws Exception {
        ObjectReader reader = null;
        if (type != null)
            reader = mapper.reader(type);
        else
            reader = mapper.reader();

        return reader.readValue(json);
    }
View Full Code Here


  public static boolean update(final Object value, final String json) {

    try {

      final ObjectReader reader = JsonUtil.json.readerForUpdating(value);
      reader.readValue(json);

      return true;
    } catch (final Exception e) {
      log.error("", e);
      return false;
View Full Code Here

          merge((ObjectNode) child, nested, mapper);
        }
      }
    }

    ObjectReader jsonReader = mapper.readerForUpdating(existingObject);
    jsonReader.readValue(root);

    return existingObject;
  }
View Full Code Here

        mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class);
       
        final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter", SimpleBeanPropertyFilter.serializeAllExcept("storedData"));

        final ObjectWriter ssWriter = mapper.writer(filters);
        final ObjectReader ssReader = mapper.reader(sus.getClass());
       
        final String susString = ssWriter.writeValueAsString(sus);
        System.out.println(susString);
        final StorelessUnivariateStatistic newSus = ssReader.readValue(susString);
       
        assertEquals(expected, newSus.getResult(), 0.1);
    }
View Full Code Here

  @SuppressWarnings("unchecked")
  private Sysprop fetchFxRatesJSON() {
    Map<String, Object> map = new HashMap<String, Object>();
    Sysprop s = new Sysprop();
    ObjectReader reader = Utils.getJsonReader(Map.class);

    try {
      HttpClient http = getHttpClient(new DefaultHttpClient());
      HttpGet httpGet = new HttpGet(SERVICE_URL);
      HttpResponse res = http.execute(httpGet);
      HttpEntity entity = res.getEntity();

      if (entity != null && isJSON(entity.getContentType().getValue())) {
        JsonNode jsonNode = reader.readTree(entity.getContent());
        if (jsonNode != null) {
          JsonNode rates = jsonNode.get("rates");
          if (rates != null) {
            map = reader.treeToValue(rates, Map.class);
            s.setId(Config.FXRATES_KEY);
            s.setProperties(map);
//            s.addProperty("fetched", Utils.formatDate("dd MM yyyy HH:mm", Locale.UK));
            dao.create(s);
          }
View Full Code Here

    @Override
    public final Object fromNonNullValue(String s) {
        try {
            final JsonWrapper jsonWrapper = objectReader.readValue(s);
            final ObjectReader typeReader = typedObjectReaders.getUnchecked(jsonWrapper.getType());
            return typeReader.readValue(jsonWrapper.getValue());
        }
        catch (JsonProcessingException e) {
            throw new IllegalArgumentException("Could not read from JSON: " + s, e);
        }
        catch (IOException e) {
View Full Code Here

    private RequestTransformer requestTransformer = new RequestTransformer();

    @Test
    public void shouldTransformSenderRequest() throws IOException {
        //given
        ObjectReader reader = JacksonUtils.getReader();
        final String json = IOUtils.toString(getClass().getResourceAsStream("/message-format-100.json"));
        StringBuilder current = new StringBuilder(json);

        //when
        final StringBuilder patched = requestTransformer.transform("/rest/sender", "100", current);

        //then
        final JsonNode patchedNode = reader.readTree(patched.toString());
        JsonNode newNode = reader.readTree(getClass().getResourceAsStream("/new-message-format.json"));

        assertEquals(newNode, patchedNode);
    }
View Full Code Here

      if (endpoint == null) {
         ObjectMapper mapper = locateMapper(type, mediaType);
         endpoint = _configForReading(mapper, annotations);
         _readers.put(key, endpoint);
      }
      ObjectReader reader = endpoint.getReader();
      JsonParser jp = _createParser(reader, entityStream);
      // If null is returned, considered to be empty stream
      if (jp == null || jp.nextToken() == null) {
         return null;
      }
      // [Issue#1]: allow 'binding' to JsonParser
      if (((Class<?>) type) == JsonParser.class) {
         return jp;
      }
      return reader.withType(genericType).readValue(jp);
   }
View Full Code Here

  @Override
  public Record deserialize(final JsonParser jsonParser,
      final DeserializationContext ctxt) throws JsonProcessingException,
      IOException {
    final ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
    final ObjectReader reader = mapper.reader().without(
        DeserializationFeature.UNWRAP_ROOT_VALUE);
    final ObjectNode recordNode = reader.readTree(jsonParser);

    final JsonNode recordTypeNode = recordNode.get(TYPE_FIELD_NAME);
    if (recordTypeNode == null) {
      throw new JsonDeserializationException(
                    JsonDeserializationExceptionCode.missingField,
          TYPE_FIELD_NAME, "resource record");
    }
    final String recordType = recordTypeNode.textValue();
    final Class<? extends Record> recordClass = recordClassesRegistry
        .get(recordType);
    if (recordClass == null) {
      throw new JsonDeserializationException(
                    JsonDeserializationExceptionCode.unknownResourceRecordType,
          recordType);
    }
    return reader.withType(recordClass).readValue(recordNode.toString());
  }
View Full Code Here

  @Override
  public Record deserialize(final JsonParser jsonParser,
      final DeserializationContext ctxt) throws JsonProcessingException,
      IOException {
    final ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
    final ObjectReader reader = mapper.reader().without(
        DeserializationFeature.UNWRAP_ROOT_VALUE);
    final ObjectNode recordNode = reader.readTree(jsonParser);

    final JsonNode recordTypeNode = recordNode.get(TYPE_FIELD_NAME);
    if (recordTypeNode == null) {
      throw new MissingFieldJsonDeserializationException(
          TYPE_FIELD_NAME, "resource record");
    }
    final String recordType = recordTypeNode.textValue();
    final Class<? extends Record> recordClass = recordClassesRegistry
        .get(recordType);
    if (recordClass == null) {
      throw new JsonDeserializationException(
                    JsonDeserializationExceptionCode.unknownResourceRecordType,
          recordType);
    }
    return reader.withType(recordClass).readValue(recordNode.toString());
  }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.ObjectReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.