/** * @since 2.7 * @deprecated Since 2.9 use {@link #setDefaultPropertyInclusion} */ @Deprecated public ObjectMapper setPropertyInclusion(JsonInclude.Value incl) { return setDefaultPropertyInclusion(incl); }
public ObjectMapperResolver() throws Exception { mapper = new ObjectMapper(); mapper.setDefaultPropertyInclusion(Value.construct(Include.NON_NULL, Include.ALWAYS)); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); }
private static JacksonJaxbJsonProvider jacksonJaxbJsonProvider() { JacksonJaxbJsonProvider jacksonJaxbJsonProvider = new JacksonJaxbJsonProvider(); ObjectMapper mapper = new ObjectMapper(); mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL)); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); // Ignore unknown properties so that deployed client remain compatible with future versions of NiFi that add new fields mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); jacksonJaxbJsonProvider.setMapper(mapper); return jacksonJaxbJsonProvider; } }
objectMapper.setDefaultPropertyInclusion(Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); System.out.println("s2s is a command line tool that can either read a list of DataPackets from stdin to send over site-to-site or write the received DataPackets to stdout"); System.out.println();
@Test public void serializingThenDeserializingWithConfiguredObjectMapperShouldWork() throws IOException { // given this.mapper.setDefaultPropertyInclusion(construct(ALWAYS, NON_NULL)).setSerializationInclusion(NON_ABSENT); UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null); // when String serialized = this.mapper.writeValueAsString(original); UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized, UsernamePasswordAuthenticationToken.class); // then assertThat(deserialized).isEqualTo(original); }
public OkHttpReplicationClient(final NiFiProperties properties) { jsonCodec.setDefaultPropertyInclusion(Value.construct(Include.NON_NULL, Include.ALWAYS)); jsonCodec.setAnnotationIntrospector(new JaxbAnnotationIntrospector(jsonCodec.getTypeFactory())); jsonSerializer = new JsonEntitySerializer(jsonCodec); xmlSerializer = new XmlEntitySerializer(); okHttpClient = createOkHttpClient(properties); }
/** * @since 2.7 * @deprecated Since 2.9 use {@link #setDefaultPropertyInclusion} */ @Deprecated public ObjectMapper setPropertyInclusion(JsonInclude.Value incl) { return setDefaultPropertyInclusion(incl); }
public ObjectMapper getJacksonMapper() { ObjectMapper result = mapper; if (result == null) { // First check (no locking) synchronized(this) { result = mapper; if (result == null) { // Second check (with locking) mapper = result = objectMapperProvider.provide().copy(); mapper.setDefaultPropertyInclusion(JsonInclude.Include.ALWAYS); } } } return result; }
/** Configures all the default options for a Batfish {@link ObjectMapper}. */ private static ObjectMapper baseMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS); mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); // Next two lines make Instant class serialize as an RFC-3339 timestamp mapper.registerModule(new JavaTimeModule()); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // This line makes Java 8's Optional type serialize mapper.registerModule(new Jdk8Module()); // See https://groups.google.com/forum/#!topic/jackson-user/WfZzlt5C2Ww // This fixes issues in which non-empty maps with keys with empty values would get omitted // entirely. See also https://github.com/batfish/batfish/issues/256 mapper.setDefaultPropertyInclusion( JsonInclude.Value.construct(Include.NON_EMPTY, Include.ALWAYS)); // This line makes Guava collections work with jackson mapper.registerModule(new GuavaModule()); return mapper; } }
objectMapper.setDefaultPropertyInclusion(Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); System.out.println("s2s is a command line tool that can either read a list of DataPackets from stdin to send over site-to-site or write the received DataPackets to stdout"); System.out.println();
objectMapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_ABSENT, JsonInclude.Include.ALWAYS));
objectMapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_ABSENT, JsonInclude.Include.ALWAYS));
objectMapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_ABSENT, JsonInclude.Include.ALWAYS));
return mapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL);
defaultMapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(Include.NON_NULL, Include.ALWAYS)); defaultMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@Test public void testMapFieldWithEmptyValue() throws JsonProcessingException { Foo foo = new Foo(); foo._map.put("key", new String[0]); ObjectMapper mapper = new ObjectMapper() .setDefaultPropertyInclusion( JsonInclude.Value.construct(Include.NON_EMPTY, Include.ALWAYS)); assertThat(mapper.writeValueAsString(foo), allOf(containsString("map"), containsString("key"))); }