List of usage examples for com.fasterxml.jackson.databind ObjectMapper setNodeFactory
public ObjectMapper setNodeFactory(JsonNodeFactory f)
From source file:uk.dsxt.voting.common.utils.web.JettyRunner.java
public static void configureMapper(ResourceConfig resourceConfig) { // create custom ObjectMapper ObjectMapper mapper = new ObjectMapper(); mapper.setNodeFactory(JsonNodeFactory.withExactBigDecimals(true)); mapper.enable(SerializationFeature.INDENT_OUTPUT); // create JsonProvider to provide custom ObjectMapper JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(mapper);//from ww w .j ava2s . c o m resourceConfig.register(provider); }
From source file:com.unboundid.scim2.common.utils.MapperFactory.java
/** * Creates a custom SCIM compatible Jackson ObjectMapper. Creating new * ObjectMapper instances are expensive so instances should be shared if * possible. This can be used to set the factory used to build new instances * of the object mapper used by the SCIM 2 SDK. * * @return an Object Mapper with the correct options set for serializing * and deserializing SCIM JSON objects. *///from w w w . jav a 2 s.c o m public static ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(new ScimJsonFactory()); // Don't serialize POJO nulls as JSON nulls. mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); // Only use ISO8601 format for dates. mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.setDateFormat(new ScimDateFormat()); // Do not care about case when de-serializing POJOs. mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); // Use the case-insensitive JsonNodes. mapper.setNodeFactory(new ScimJsonNodeFactory()); for (DeserializationFeature feature : deserializationCustomFeatures.keySet()) { mapper.configure(feature, deserializationCustomFeatures.get(feature)); } for (JsonGenerator.Feature feature : jsonGeneratorCustomFeatures.keySet()) { mapper.configure(feature, jsonGeneratorCustomFeatures.get(feature)); } for (JsonParser.Feature feature : jsonParserCustomFeatures.keySet()) { mapper.configure(feature, jsonParserCustomFeatures.get(feature)); } for (MapperFeature feature : mapperCustomFeatures.keySet()) { mapper.configure(feature, mapperCustomFeatures.get(feature)); } for (SerializationFeature feature : serializationCustomFeatures.keySet()) { mapper.configure(feature, serializationCustomFeatures.get(feature)); } return mapper; }
From source file:com.helger.wsdlgen.exchange.InterfaceReader.java
@Nonnull private static ObjectMapper _createJSONFactory() { final ObjectMapper aObjectMapper = new ObjectMapper(); // Necessary configuration to allow control characters inside of JSON // strings (like newline etc.) aObjectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true); // Feature that determines whether parser will allow use of unquoted field // names (which is allowed by Javascript, but not by JSON specification). aObjectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); // Always use BigDecimal aObjectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); // As of 2.1.4 BigDecimals are compacted by default - with this method // everything stays as it was aObjectMapper.setNodeFactory(JsonNodeFactory.withExactBigDecimals(true)); return aObjectMapper; }
From source file:org.jmxtrans.embedded.util.json.PlaceholderEnabledJsonNodeFactoryTest.java
@Test public void testWithPlaceholders() throws Exception { System.setProperty("graphite.host", "graphite.www.private.mycompany.com"); System.setProperty("server.name", "tomcat1"); try {//from w ww.ja v a 2s.c o m String configurationUrl = "org/jmxtrans/embedded/util/json/jmxtrans-placeholder-test.json"; InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(configurationUrl); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setNodeFactory(new PlaceholderEnabledJsonNodeFactory()); JsonNode rootNode = objectMapper.readValue(in, JsonNode.class); JsonNode outputWritersNode = rootNode.path("outputWriters"); JsonNode outputWriterNode = outputWritersNode.get(1); assertThat(outputWriterNode.path("@class").asText(), is("org.jmxtrans.embedded.output.GraphiteWriter")); JsonNode settingsNode = outputWriterNode.path("settings"); assertThat(settingsNode.path("host").asText(), is("graphite.www.private.mycompany.com")); assertThat(settingsNode.path("port").asInt(), is(2003)); assertThat(settingsNode.path("namePrefix").asText(), is("servers.tomcat1.")); } finally { System.getProperties().remove("graphite.host"); System.getProperties().remove("server.name"); } }