/** * Method for disabling automatic inclusion of type information; if so, only * explicitly annotated types (ones with * {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) will have * additional embedded type information. */ public ObjectMapper disableDefaultTyping() { return setDefaultTyping(null); }
mapTyper.init(JsonTypeInfo.Id.CLASS, null); mapTyper.inclusion(JsonTypeInfo.As.PROPERTY); mapObjectMapper.setDefaultTyping(mapTyper);
mapTyper.init(JsonTypeInfo.Id.CLASS, null); mapTyper.inclusion(JsonTypeInfo.As.PROPERTY); mapObjectMapper.setDefaultTyping(mapTyper);
return setDefaultTyping(typer);
public static void enableDefaultTyping(ObjectMapper mapper) { if (mapper != null) { TypeResolverBuilder<?> typeBuilder = mapper.getDeserializationConfig().getDefaultTyper(null); if (typeBuilder == null) { mapper.setDefaultTyping(createWhitelistedDefaultTyping()); } } }
public static void enableDefaultTyping(ObjectMapper mapper) { if (mapper != null) { TypeResolverBuilder<?> typeBuilder = mapper.getDeserializationConfig().getDefaultTyper(null); if (typeBuilder == null) { mapper.setDefaultTyping(createWhitelistedDefaultTyping()); } } }
objectMapper.setDefaultTyping(this.defaultTyping);
/** * Method for enabling automatic inclusion of type information -- needed * for proper deserialization of polymorphic types (unless types * have been annotated with {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) -- * using "As.PROPERTY" inclusion mechanism and specified property name * to use for inclusion (default being "@class" since default type information * always uses class name as type identifier) *<p> * NOTE: use of Default Typing can be a potential security risk if incoming * content comes from untrusted sources, and it is recommended that this * is either not done, or, if enabled, use {@link #setDefaultTyping} * passing a custom {@link TypeResolverBuilder} implementation that white-lists * legal types to use. */ public ObjectMapper enableDefaultTypingAsProperty(DefaultTyping applicability, String propertyName) { TypeResolverBuilder<?> typer = new DefaultTypeResolverBuilder(applicability); // we'll always use full class name, when using defaulting typer = typer.init(JsonTypeInfo.Id.CLASS, null); typer = typer.inclusion(JsonTypeInfo.As.PROPERTY); typer = typer.typeProperty(propertyName); return setDefaultTyping(typer); }
objectMapper.setDefaultTyping(this.defaultTyping);
public JsonMessageSerializer() { actorReferenceModule = new ActorReferenceModule(DefaultDescriptorFactory.get()); mapper.registerModule(actorReferenceModule); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); TypeResolverBuilder<?> typer = new ClassIdTypeResolverBuilder(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT); typer = typer.init(JsonTypeInfo.Id.NAME, null); typer = typer.inclusion(JsonTypeInfo.As.PROPERTY); mapper.setDefaultTyping(typer); }
protected ObjectMapper getObjectMapperForSerialization() { ObjectMapper mapper = new ObjectMapper(); StdTypeResolverBuilder typeResolverBuilder = new ObjectMapper.DefaultTypeResolverBuilder(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE); typeResolverBuilder = typeResolverBuilder.inclusion(JsonTypeInfo.As.PROPERTY); typeResolverBuilder.init(JsonTypeInfo.Id.CLASS, new ClassNameIdResolver(SimpleType.construct(Base.class), TypeFactory.defaultInstance())); mapper.setDefaultTyping(typeResolverBuilder); return mapper; }
protected ObjectMapper getObjectMapperForDeserialization() { ObjectMapper mapper = new ObjectMapper(); StdTypeResolverBuilder typeResolverBuilder = new ObjectMapper.DefaultTypeResolverBuilder(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE); typeResolverBuilder = typeResolverBuilder.inclusion(JsonTypeInfo.As.PROPERTY); typeResolverBuilder.init(JsonTypeInfo.Id.CLASS, new ClassNameIdResolver(SimpleType.construct(Base.class), TypeFactory.defaultInstance()) { private HashMap<Class, Class> classes = new HashMap<Class, Class>() { { put(ConcreteA.class, ConcreteAAdapter.class); put(ConcreteB.class, ConcreteBAdapter.class); put(ConcreteC.class, ConcreteCAdapter.class); } }; @Override public String idFromValue(Object value) { return (classes.containsKey(value.getClass())) ? value.getClass().getName() : null; } @Override public JavaType typeFromId(String id) { try { return classes.get(Class.forName(id)) == null ? super.typeFromId(id) : _typeFactory.constructSpecializedType(_baseType, classes.get(Class.forName(id))); } catch (ClassNotFoundException e) { // todo catch the e } return super.typeFromId(id); } }); mapper.setDefaultTyping(typeResolverBuilder); return mapper; }
ObjectMapper mapper = new Jackson2JsonObjectMapper().getObjectMapper(); mapper.setDefaultTyping(new WhitelistTypeResolverBuilder(trustedPackages));
/** * Method for disabling automatic inclusion of type information; if so, only * explicitly annotated types (ones with * {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) will have * additional embedded type information. */ public ObjectMapper disableDefaultTyping() { return setDefaultTyping(null); }
/** * Method for disabling automatic inclusion of type information; if so, only * explicitly annotated types (ones with * {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) will have * additional embedded type information. */ public ObjectMapper disableDefaultTyping() { return setDefaultTyping(null); }
/** * Method for disabling automatic inclusion of type information; if so, only * explicitly annotated types (ones with * {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) will have * additional embedded type information. */ public ObjectMapper disableDefaultTyping() { return setDefaultTyping(null); }
/** * Method for disabling automatic inclusion of type information; if so, only * explicitly annotated types (ones with * {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) will have * additional embedded type information. */ public ObjectMapper disableDefaultTyping() { return setDefaultTyping(null); }
/** * Method for disabling automatic inclusion of type information; if so, only * explicitly annotated types (ones with * {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) will have * additional embedded type information. */ public ObjectMapper disableDefaultTyping() { return setDefaultTyping(null); }
/** * Method for disabling automatic inclusion of type information; if so, only * explicitly annotated types (ones with * {@link com.fasterxml.jackson.annotation.JsonTypeInfo}) will have * additional embedded type information. */ public ObjectMapper disableDefaultTyping() { return setDefaultTyping(null); }
@Autowired public AppConfigService(KvMapperFactory kvMapperFactory, ObjectMapper objectMapper) { // we must use custom configuration of mapper, but need use most options and modules from global mapper this.objectMapper = objectMapper.copy(); StdTypeResolverBuilder trb = new ObjectMapper.DefaultTypeResolverBuilder(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT); trb.init(JsonTypeInfo.Id.CLASS, new CustomTypeIdResolver()).inclusion(JsonTypeInfo.As.PROPERTY); this.objectMapper.setDefaultTyping(trb); this.objectMapper.registerModule(new KvSupportModule(kvMapperFactory)); }