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 ObjectMapperResolver() throws Exception { mapper = new ObjectMapper(); mapper.setDefaultPropertyInclusion(Value.construct(Include.NON_NULL, Include.ALWAYS)); mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); }
protected SimpleBeanPropertyDefinition(AnnotatedMember member, PropertyName fullName, AnnotationIntrospector intr, PropertyMetadata metadata, JsonInclude.Include inclusion) { this(member, fullName, intr, metadata, ((inclusion == null) || (inclusion == JsonInclude.Include.USE_DEFAULTS) ? EMPTY_INCLUDE : JsonInclude.Value.construct(inclusion, null))); }
@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"))); }
@Override // @since 2.7 public JsonInclude.Value findPropertyInclusion(Annotated a) { JsonInclude.Include incl = findSerializationInclusion(a, null); if (incl == null) { return JsonInclude.Value.empty(); } return JsonInclude.Value.construct(incl, null); }
@Override // @since 2.7 public JsonInclude.Value findPropertyInclusion(Annotated a) { JsonInclude.Include incl = findSerializationInclusion(a, null); if (incl == null) { return JsonInclude.Value.empty(); } return JsonInclude.Value.construct(incl, null); }
/** * Short-cut for: *<pre> * setDefaultPropertyInclusion(JsonInclude.Value.construct(incl, incl)); *</pre> * * @since 2.9 (basically rename of <code>setPropertyInclusion</code>) */ public ObjectMapper setDefaultPropertyInclusion(JsonInclude.Include incl) { _configOverrides.setDefaultInclusion(JsonInclude.Value.construct(incl, incl)); return this; }
/** * Mutant factory that will either *<ul> * <li>Set <code>value</code> as <code>USE_DEFAULTS</code> * and <code>valueFilter</code> to <code>filter</code> (if filter not null); * or</li> * <li>Set <code>value</code> as <code>ALWAYS</code> (if filter null) * </li> * </ul> */ public Value withValueFilter(Class<?> filter) { Include incl; if (filter == null || filter == Void.class) { // clear filter incl = Include.USE_DEFAULTS; filter = null; } else { incl = Include.CUSTOM; } return construct(incl, _contentInclusion, filter, _contentFilter); }
/** * Mutant factory that will either *<ul> * <li>Set <code>content</code> as <code>USE_DEFAULTS</code> * and <code>contentFilter</code> to <code>filter</code> (if filter not null); * or</li> * <li>Set <code>content</code> as <code>ALWAYS</code> (if filter null) * </li> * </ul> */ public Value withContentFilter(Class<?> filter) { Include incl; if (filter == null || filter == Void.class) { // clear filter incl = Include.USE_DEFAULTS; filter = null; } else { incl = Include.CUSTOM; } return construct(_valueInclusion, incl, _valueFilter, filter); }
@Override // @since 2.7 public JsonInclude.Value findPropertyInclusion(Annotated a) { JsonInclude.Include incl = _serializationInclusion(a, null); if (incl == null) { return JsonInclude.Value.empty(); } return JsonInclude.Value.construct(incl, null); }
/** * Mutant factory that will either *<ul> * <li>Set <code>content</code> as <code>USE_DEFAULTS</code> * and <code>contentFilter</code> to <code>filter</code> (if filter not null); * or</li> * <li>Set <code>content</code> as <code>ALWAYS</code> (if filter null) * </li> * </ul> * * @since 2.9 */ public Value withContentFilter(Class<?> filter) { Include incl; if (filter == null || filter == Void.class) { // clear filter incl = Include.USE_DEFAULTS; filter = null; } else { incl = Include.CUSTOM; } return construct(_valueInclusion, incl, _valueFilter, filter); }
/** * Mutant factory that will either *<ul> * <li>Set <code>value</code> as <code>USE_DEFAULTS</code> * and <code>valueFilter</code> to <code>filter</code> (if filter not null); * or</li> * <li>Set <code>value</code> as <code>ALWAYS</code> (if filter null) * </li> * </ul> * * @since 2.9 */ public Value withValueFilter(Class<?> filter) { Include incl; if (filter == null || filter == Void.class) { // clear filter incl = Include.USE_DEFAULTS; filter = null; } else { incl = Include.CUSTOM; } return construct(incl, _contentInclusion, filter, _contentFilter); }
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); }
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; } }
/** * Mutant factory that will either *<ul> * <li>Set <code>content</code> as <code>USE_DEFAULTS</code> * and <code>contentFilter</code> to <code>filter</code> (if filter not null); * or</li> * <li>Set <code>content</code> as <code>ALWAYS</code> (if filter null) * </li> * </ul> * * @since 2.9 */ public Value withContentFilter(Class<?> filter) { Include incl; if (filter == null || filter == Void.class) { // clear filter incl = Include.USE_DEFAULTS; filter = null; } else { incl = Include.CUSTOM; } return construct(_valueInclusion, incl, _valueFilter, filter); }
/** * Mutant factory that will either *<ul> * <li>Set <code>value</code> as <code>USE_DEFAULTS</code> * and <code>valueFilter</code> to <code>filter</code> (if filter not null); * or</li> * <li>Set <code>value</code> as <code>ALWAYS</code> (if filter null) * </li> * </ul> * * @since 2.9 */ public Value withValueFilter(Class<?> filter) { Include incl; if (filter == null || filter == Void.class) { // clear filter incl = Include.USE_DEFAULTS; filter = null; } else { incl = Include.CUSTOM; } return construct(incl, _contentInclusion, filter, _contentFilter); }
/** * Method called to create instance for virtual properties. * * @since 2.5 */ public static SimpleBeanPropertyDefinition construct(MapperConfig<?> config, AnnotatedMember member, PropertyName name, PropertyMetadata metadata, JsonInclude.Include inclusion) { JsonInclude.Value inclValue = ((inclusion == null) || (inclusion == JsonInclude.Include.USE_DEFAULTS)) ? EMPTY_INCLUDE : JsonInclude.Value.construct(inclusion, null); return new SimpleBeanPropertyDefinition(config.getAnnotationIntrospector(), member, name, metadata, inclValue); }
/** * Short-cut for: *<pre> * setDefaultPropertyInclusion(JsonInclude.Value.construct(incl, incl)); *</pre> * * @since 2.9 (basically rename of <code>setPropertyInclusion</code>) */ public ObjectMapper setDefaultPropertyInclusion(JsonInclude.Include incl) { _configOverrides.setDefaultInclusion(JsonInclude.Value.construct(incl, incl)); return this; }
/** * Convenience method, equivalent to calling: *<pre> * setPropertyInclusion(JsonInclude.Value.construct(incl, incl)); *</pre> *<p> * NOTE: behavior differs slightly from 2.8, where second argument was * implied to be <code>JsonInclude.Include.ALWAYS</code>. */ public ObjectMapper setSerializationInclusion(JsonInclude.Include incl) { setPropertyInclusion(JsonInclude.Value.construct(incl, incl)); return this; }