Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString()


      ObjectMapper mapper = new ObjectMapper();
            if (debug) {
                ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
                return writer.writeValueAsString(object);
            } else {
                return mapper.writeValueAsString(object);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here


    String json = null;
    ObjectMapper mapper = new ObjectMapper();
   
    try {
      // write JSON to a file
      json = mapper.writeValueAsString((Object)map);
   
    } catch ( JsonProcessingException e ) {
      LOG.failedToSerializeMapToJSON( map, e );
    }
    return json;
View Full Code Here

    String json = null;
    ObjectMapper mapper = new ObjectMapper();
   
    try {
      // write JSON to a file
      json = mapper.writeValueAsString((Object)registry);
   
    } catch ( JsonProcessingException e ) {
      e.printStackTrace(); //TODO: I18N
    }
    return json;
View Full Code Here

    String configObjectString;
    try {
      if (config.isDebug()) {
        configObjectString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(modelObject);
      } else {
        configObjectString = mapper.writeValueAsString(modelObject);
      }

    } catch (JsonGenerationException e) {
      throw new RuntimeException(e);
    } catch (JsonMappingException e) {
View Full Code Here

   * @return json字符串,若序列化失败,则返回null
   */
  public static String jsonSerialize(Object value) {
    ObjectMapper objectMapper = new ObjectMapper();
    try {
      return objectMapper.writeValueAsString(value);
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    }
  }
View Full Code Here

        ObjectMapper mapper = new ObjectMapper();
        RowPageBuilder builder = RowPageBuilder.rowPageBuilder(BigintType.BIGINT, VarcharType.VARCHAR, VarcharType.VARCHAR);
        Random rand = new Random(0);
        for (int i = 0; i < datapoints; i++) {
            long label = rand.nextDouble() < 0.5 ? 0 : 1;
            builder.row(label, mapper.writeValueAsString(ImmutableMap.of(0, label + rand.nextGaussian())), "C=1");
        }

        return builder.build();
    }
}
View Full Code Here

            null, null, null, null, null, null, null, null, false, false
        ),
        null, null, null, null
    );

    String json = jsonMapper.writeValueAsString(schema);

    FireDepartment newSchema = jsonMapper.readValue(json, FireDepartment.class);

    Assert.assertEquals(schema.getDataSchema().getDataSource(), newSchema.getDataSchema().getDataSource());
  }
View Full Code Here

  {
    CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory("billy", ImmutableList.of("b", "a", "c"), true);
    ObjectMapper objectMapper = new DefaultObjectMapper();
    Assert.assertEquals(
        factory,
        objectMapper.readValue(objectMapper.writeValueAsString(factory), AggregatorFactory.class)
    );
  }
}
View Full Code Here

  }

  @Test
  public void testJackson() throws IOException {
    ObjectMapper mapperSave = new ObjectMapper();
    String jsonStr = mapperSave.writeValueAsString(playerData);

    System.out.println(CLASS_UNDER_TEST + " - Jackson length: " + jsonStr.length() + " chars");
    if (PRINT_OUTPUT) {
      System.out.println(jsonStr);
    }
View Full Code Here

  @Test
  @Ignore("This is an object model with circular references, auto serialize does not work")
  public void testJackson() throws IOException {
    ObjectMapper mapperSave = new ObjectMapper();
    String jsonStr = mapperSave.writeValueAsString(game);

    System.out.println(CLASS_UNDER_TEST + " - Jackson length: " + jsonStr.length() + " chars");
    if (PRINT_OUTPUT) {
      System.out.println(jsonStr);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.