public EntitySerializer() { try { mapper = new ObjectMapper( f ); // mapper.enable(SerializationFeature.INDENT_OUTPUT); don't indent output, // causes slowness mapper.enableDefaultTypingAsProperty( ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, "@class" ); } catch ( Exception e ) { throw new RuntimeException( "Error setting up mapper", e ); } }
/** * Creates {@link GenericJackson2JsonRedisSerializer} and configures {@link ObjectMapper} for default typing using the * given {@literal name}. In case of an {@literal empty} or {@literal null} String the default * {@link JsonTypeInfo.Id#CLASS} will be used. * * @param classPropertyTypeName Name of the JSON property holding type information. Can be {@literal null}. */ public GenericJackson2JsonRedisSerializer(@Nullable String classPropertyTypeName) { this(new ObjectMapper()); // simply setting {@code mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)} does not help here since we need // the type hint embedded for deserialization using the default typing feature. registerNullValueSerializer(mapper, classPropertyTypeName); if (StringUtils.hasText(classPropertyTypeName)) { mapper.enableDefaultTypingAsProperty(DefaultTyping.NON_FINAL, classPropertyTypeName); } else { mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY); } }
public EntitySerializer( final SerializationFig serializationFig, final MetricsFactory metricsFactory) { this.serializationFig = serializationFig; // SimpleModule listModule = new SimpleModule("ListFieldModule", new Version(1, 0, 0, null,null,null)) // .addAbstractTypeMapping(ListField.class, ArrayField.class); // MAPPER.registerModule(listModule); // causes slowness MAPPER.enableDefaultTypingAsProperty( ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, "@class" ); this.bytesOutHistorgram = metricsFactory.getHistogram(MvccEntitySerializationStrategyV2Impl.class, "bytes.out"); this.bytesInHistorgram = metricsFactory.getHistogram(MvccEntitySerializationStrategyV2Impl.class, "bytes.in"); this.bytesOutTimer = metricsFactory.getTimer(MvccEntitySerializationStrategyV2Impl.class, "bytes.out"); }
public EntitySerializer( final SerializationFig serializationFig, final MetricsFactory metricsFactory) { this.serializationFig = serializationFig; this.bytesOutHistorgram = metricsFactory.getHistogram(MvccEntitySerializationStrategyV3Impl.class, "bytes.out"); this.bytesOutTimer = metricsFactory.getTimer(MvccEntitySerializationStrategyV3Impl.class, "bytes.out"); this.bytesInHistorgram = metricsFactory.getHistogram(MvccEntitySerializationStrategyV3Impl.class, "bytes.in"); // mapper.enable(SerializationFeature.INDENT_OUTPUT); don't indent output, // causes slowness MAPPER.enableDefaultTypingAsProperty( ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, "@class" ); }
mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, "@class");
mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, "@class");
public JacksonResourceFormatter() { mapper = new ObjectMapper(); mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, "@type"); }
ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "class"); // Note Object.class as second parameter. Jackson will find the "class" // property in the JSON and use it to determine which class to make. MyClass foo = (MyClass) objectMapper.readValue(jsonString, Object.class);
public SimpleFileBasedEventStore(String eventStoreFile) throws IOException { objectMapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, "type"); this.eventStoreFile = init(eventStoreFile); }
ObjectMapper om = new ObjectMapper(); om.enableDefaultTypingAsProperty(DefaultTyping.OBJECT_AND_NON_CONCRETE, "__class"); IPerson value = new MyPerson(); String s = om.writeValueAsString(value); IPerson d = om.readValue(s, IPerson.class);
/** * Creates {@link GenericJackson2JsonRedisSerializer} and configures {@link ObjectMapper} for default typing using the * given {@literal name}. In case of an {@literal empty} or {@literal null} String the default * {@link JsonTypeInfo.Id#CLASS} will be used. * * @param classPropertyTypeName Name of the JSON property holding type information. Can be {@literal null}. */ public GenericJackson2JsonRedisSerializer(@Nullable String classPropertyTypeName) { this(new ObjectMapper()); // simply setting {@code mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)} does not help here since we need // the type hint embedded for deserialization using the default typing feature. mapper.registerModule(new SimpleModule().addSerializer(new NullValueSerializer(classPropertyTypeName))); if (StringUtils.hasText(classPropertyTypeName)) { mapper.enableDefaultTypingAsProperty(DefaultTyping.NON_FINAL, classPropertyTypeName); } else { mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY); } }
/** * Creates {@link GenericJackson2JsonRedisSerializer} and configures {@link ObjectMapper} for default typing using the * given {@literal name}. In case of an {@literal empty} or {@literal null} String the default * {@link JsonTypeInfo.Id#CLASS} will be used. * * @param classPropertyTypeName Name of the JSON property holding type information. Can be {@literal null}. */ public GenericJackson2JsonRedisSerializer(@Nullable String classPropertyTypeName) { this(new ObjectMapper()); // simply setting {@code mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)} does not help here since we need // the type hint embedded for deserialization using the default typing feature. mapper.registerModule(new SimpleModule().addSerializer(new NullValueSerializer(classPropertyTypeName))); if (StringUtils.hasText(classPropertyTypeName)) { mapper.enableDefaultTypingAsProperty(DefaultTyping.NON_FINAL, classPropertyTypeName); } else { mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY); } }
private void provisionAccessControl(Properties properties, String domain, String[] interfaceNames) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); List<MasterAccessControlEntry> allEntries = new ArrayList<>(); for (String interfaceName : interfaceNames) { MasterAccessControlEntry newMasterAccessControlEntry = new MasterAccessControlEntry("*", domain, interfaceName, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, "*", Permission.YES, new Permission[]{ joynr.infrastructure.DacTypes.Permission.YES }); allEntries.add(newMasterAccessControlEntry); } MasterAccessControlEntry[] provisionedAccessControlEntries = allEntries.toArray(new MasterAccessControlEntry[allEntries.size()]); String provisionedAccessControlEntriesAsJson; try { provisionedAccessControlEntriesAsJson = objectMapper.writeValueAsString(provisionedAccessControlEntries); properties.setProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, provisionedAccessControlEntriesAsJson); } catch (JsonProcessingException e) { LOG.error("Error parsing JSON.", e); } }
@Override public ObjectMapper createMapper() { final ObjectMapper om = new ObjectMapper(); om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); if (embedTypes) om.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, GraphSONTokens.CLASS); if (normalize) om.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); // this provider toStrings all unknown classes and converts keys in Map objects that are Object to String. final DefaultSerializerProvider provider = new GraphSONSerializerProvider(); provider.setDefaultKeySerializer(new GraphSONModule.GraphSONKeySerializer()); om.setSerializerProvider(provider); om.registerModule(new GraphSONModule(normalize)); customModules.forEach(om::registerModule); // plugin external serialization modules if (loadCustomSerializers) om.findAndRegisterModules(); // keep streams open to accept multiple values (e.g. multiple vertices) om.getFactory().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); return om; }
public JsonMessageSerializerModule() { objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); objectMapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true); // objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); TypeResolverBuilder<?> joynrTypeResolverBuilder = objectMapper.getSerializationConfig() .getDefaultTyper(SimpleType.construct(Object.class)); SimpleModule module = new SimpleModule("NonTypedModule", new Version(1, 0, 0, "", "", "")); module.addSerializer(new JoynrEnumSerializer()); module.addSerializer(new JoynrListSerializer()); module.addSerializer(new JoynrArraySerializer()); TypeDeserializer typeDeserializer = joynrTypeResolverBuilder.buildTypeDeserializer(objectMapper.getDeserializationConfig(), SimpleType.construct(Object.class), null); module.addDeserializer(Request.class, new RequestDeserializer(objectMapper)); module.addDeserializer(OneWayRequest.class, new OneWayRequestDeserializer(objectMapper)); module.addDeserializer(Object.class, new JoynrUntypedObjectDeserializer(typeDeserializer)); module.setMixInAnnotation(Throwable.class, ThrowableMixIn.class); objectMapper.registerModule(module); }
DefaultTyping defaultTyping = DefaultTyping .valueOf(defaultTypeDefs[0]); mapper.enableDefaultTypingAsProperty(defaultTyping, defaultTypeDefs[1]); getLogger().info(