Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectReader


  @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


    public void importBsonDumpFileIntoCollection() throws Exception {

        InputStream bsonDump = getClass().getClassLoader().getResourceAsStream("1000friends.bson");
        BsonFactory bsonFactory = new BsonFactory();
        //bsonFactory.enable(BsonParser.Feature.HONOR_DOCUMENT_LENGTH); // fails when enabled
        ObjectReader reader = new ObjectMapper(bsonFactory).reader(BasicBSONObject.class);

        MappingIterator<BSONObject> iterator = reader.readValues(bsonDump);
        try {
            while (iterator.hasNext()) {
                BSONObject bsonObject = iterator.next();
                collection.withWriteConcern(WriteConcern.SAFE).save(bsonObject);
            }
View Full Code Here

                }
            }
            if (json != null) {
                Object dto = null;
                try {
                    ObjectReader reader = objectMapper.reader();
                    JsonNode tree = null;
                    if (json != null) {
                        tree = reader.readTree(new ByteArrayInputStream(json));
                        if (tree != null) {
                            JsonNode kindNode = tree.get("kind");
                            if (kindNode != null) {
                                String kind = kindNode.asText();
                                if (Objects.equal("Pod", kind)) {
View Full Code Here

     * from the Kubernetes REST API or
     * {@link JsonNode} if it cannot be recognised.
     */
    public static Object loadJson(byte[] json) throws IOException {
        if (json != null && json.length > 0) {
            ObjectReader reader = objectMapper.reader();
            JsonNode tree = reader.readTree(new ByteArrayInputStream(json));
            if (tree != null) {
                JsonNode kindNode = tree.get("kind");
                if (kindNode != null) {
                    String kind = kindNode.asText();
                    if (Objects.equal("Pod", kind)) {
View Full Code Here

       
        String xml = w.writeValueAsString(input);

//System.err.println("DEBUG: Xml == "+xml);

        ObjectReader r = MAPPER.reader(MediaItem.class);
        MediaItem result = r.readValue(xml);
        assertNotNull(result);
        assertEquals(content.getTitle(), result.getContent().getTitle());
    }
View Full Code Here

    public void testSimpleViaObjectReader() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        XmlMapper xmlMapper = new XmlMapper();

        ObjectReader detecting = mapper.reader(POJO.class);
        detecting = detecting
                .withFormatDetection(detecting, xmlMapper.reader(POJO.class));
        POJO pojo = detecting.readValue(utf8Bytes("<POJO><y>3</y><x>1</x></POJO>"));
        assertNotNull(pojo);
        assertEquals(1, pojo.x);
        assertEquals(3, pojo.y);
    }
View Full Code Here

        ListPOJO list = new ListPOJO();
        list.v.add(new POJO(1, 2));
        list.v.add(new POJO(3, 4));
        String xml = xmlMapper.writeValueAsString(list);

        ObjectReader detecting = mapper.reader(ListPOJO.class);
        ListPOJO resultList = detecting
                .withFormatDetection(detecting, xmlMapper.reader(ListPOJO.class))
                .readValue(utf8Bytes(xml));
        assertNotNull(resultList);
        assertEquals(2, resultList.v.size());
    }
View Full Code Here

      return (String)executeScript("return JSON.stringify(JSON.decycle(function(arguments){"+ script + "}(arguments)));", params);
    }   
   
    private <T> T deserializeJsonAs(Class<T> classOfT, final String objString){
      ObjectMapper mapper = getMapper();
      ObjectReader reader = mapper.reader(classOfT);
      if (inject != null){
        reader = reader.with(inject);
      }
      try {
        return reader.readValue(objString);
    } catch (JsonParseException e) {
      throw new WebDriverException(e);
    } catch (JsonMappingException e) {
      throw new WebDriverException(e);
    } catch (IOException e) {
View Full Code Here

    }
    }
   
    private <T> List<T> deserializeJsonAsListOf(Class<T> classOfT, final String objString){
      ObjectMapper mapper = getMapper();
      ObjectReader reader = mapper.reader(TypeFactory.defaultInstance().constructCollectionType(List.class, classOfT));
      if (inject != null){
        reader = reader.with(inject);
      }
      try {
        return reader.readValue(objString);
    } catch (JsonParseException e) {
      throw new WebDriverException(e);
    } catch (JsonMappingException e) {
      throw new WebDriverException(e);
    } catch (IOException e) {
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

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.