com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProviderApplication.java From joynr with Apache License 2.0 | 6 votes |
private static void provisionAccessControl(Properties properties, String domain) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); MasterAccessControlEntry newMasterAccessControlEntry = new MasterAccessControlEntry("*", domain, ProviderAnnotations.getInterfaceName(Provider.class), TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, "*", Permission.YES, new Permission[]{ Permission.YES }); MasterAccessControlEntry[] provisionedAccessControlEntries = { newMasterAccessControlEntry }; String provisionedAccessControlEntriesAsJson = objectMapper.writeValueAsString(provisionedAccessControlEntries); properties.setProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, provisionedAccessControlEntriesAsJson); }
Example #2
Source File: EchoProviderApplication.java From joynr with Apache License 2.0 | 6 votes |
private static Properties createAppConfig() throws Exception { Properties appConfig = new Properties(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); MasterAccessControlEntry newMasterAccessControlEntry = new MasterAccessControlEntry("*", invocationParams.getDomain(), ProviderAnnotations.getInterfaceName(EchoProviderImpl.class), TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, "*", Permission.YES, new Permission[]{ Permission.YES }); MasterAccessControlEntry[] provisionedAccessControlEntries = { newMasterAccessControlEntry }; String provisionedAccessControlEntriesAsJson = objectMapper.writeValueAsString(provisionedAccessControlEntries); appConfig.setProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, provisionedAccessControlEntriesAsJson); return appConfig; }
Example #3
Source File: IltProviderApplication.java From joynr with Apache License 2.0 | 6 votes |
private static void provisionAccessControl(Properties properties, String domain) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); MasterAccessControlEntry newMasterAccessControlEntry = new MasterAccessControlEntry("*", domain, ProviderAnnotations.getInterfaceName(IltProvider.class), TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, "*", Permission.YES, new Permission[]{ Permission.YES }); MasterAccessControlEntry[] provisionedAccessControlEntries = { newMasterAccessControlEntry }; String provisionedAccessControlEntriesAsJson = objectMapper.writeValueAsString(provisionedAccessControlEntries); properties.setProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, provisionedAccessControlEntriesAsJson); }
Example #4
Source File: MyRadioProviderApplication.java From joynr with Apache License 2.0 | 6 votes |
private static void provisionAccessControl(Properties properties, String domain) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); MasterAccessControlEntry newMasterAccessControlEntry = new MasterAccessControlEntry("*", domain, ProviderAnnotations.getInterfaceName(MyRadioProvider.class), TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, "*", Permission.YES, new Permission[]{ Permission.YES }); MasterAccessControlEntry[] provisionedAccessControlEntries = { newMasterAccessControlEntry }; String provisionedAccessControlEntriesAsJson = objectMapper.writeValueAsString(provisionedAccessControlEntries); properties.setProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, provisionedAccessControlEntriesAsJson); }
Example #5
Source File: MyGpsProviderApplication.java From joynr with Apache License 2.0 | 6 votes |
private static void provisionAccessControl(Properties properties, String domain) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); MasterAccessControlEntry newMasterAccessControlEntry = new MasterAccessControlEntry("*", domain, ProviderAnnotations.getInterfaceName(MyGpsProvider.class), TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, "*", Permission.YES, new Permission[]{ Permission.YES }); MasterAccessControlEntry[] provisionedAccessControlEntries = { newMasterAccessControlEntry }; String provisionedAccessControlEntriesAsJson = objectMapper.writeValueAsString(provisionedAccessControlEntries); properties.setProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, provisionedAccessControlEntriesAsJson); }
Example #6
Source File: MonetaryAmountDeserializerTest.java From jackson-datatype-money with MIT License | 6 votes |
@ParameterizedTest @MethodSource("data") void shouldDeserializeWithTypeInformation(final Class<M> type, final Configurer configurer) throws IOException { final ObjectMapper unit = unit(configurer) .activateDefaultTyping( BasicPolymorphicTypeValidator.builder().build(), DefaultTyping.OBJECT_AND_NON_CONCRETE, JsonTypeInfo.As.EXISTING_PROPERTY) .disable(FAIL_ON_UNKNOWN_PROPERTIES); final String content = "{\"type\":\"org.javamoney.moneta.Money\",\"amount\":29.95,\"currency\":\"EUR\"}"; final M amount = unit.readValue(content, type); // type information is ignored?! assertThat(amount, is(instanceOf(type))); }
Example #7
Source File: MessagingTest.java From joynr with Apache License 2.0 | 6 votes |
private ObjectMapper getObjectMapper() { objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); // 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)); return objectMapper; }
Example #8
Source File: AbstractBounceProxyServerTest.java From joynr with Apache License 2.0 | 6 votes |
private ObjectMapper getObjectMapper() { objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); // 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()); TypeDeserializer typeDeserializer = joynrTypeResolverBuilder.buildTypeDeserializer(objectMapper.getDeserializationConfig(), SimpleType.construct(Object.class), null); module.addDeserializer(Object.class, new JoynrUntypedObjectDeserializer(typeDeserializer)); objectMapper.registerModule(module); return objectMapper; }
Example #9
Source File: RedisTemplateConfiguration.java From mica with GNU Lesser General Public License v3.0 | 6 votes |
/** * value 值 序列化 * * @return RedisSerializer */ @Bean @ConditionalOnMissingBean(RedisSerializer.class) public RedisSerializer<Object> redisSerializer(MicaRedisProperties properties, ObjectProvider<ObjectMapper> objectProvider) { MicaRedisProperties.SerializerType serializerType = properties.getSerializerType(); if (MicaRedisProperties.SerializerType.JDK == serializerType) { return new JdkSerializationRedisSerializer(); } // jackson findAndRegisterModules,use copy ObjectMapper objectMapper = objectProvider.getIfAvailable(ObjectMapper::new).copy(); // findAndRegisterModules objectMapper.findAndRegisterModules(); // class type info to json GenericJackson2JsonRedisSerializer.registerNullValueSerializer(objectMapper, null); objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), DefaultTyping.NON_FINAL, As.PROPERTY); return new GenericJackson2JsonRedisSerializer(objectMapper); }
Example #10
Source File: AdvancedAnnotationsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenUsingJsonTypeIdAnnotation_thenCorrect() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); mapper.enableDefaultTyping(DefaultTyping.NON_FINAL); TypeIdBean bean = new TypeIdBean(6, "Type Id Bean"); String jsonString = mapper.writeValueAsString(bean); assertThat(jsonString, containsString("Type Id Bean")); }
Example #11
Source File: JsonMessageSerializerModule.java From joynr with Apache License 2.0 | 5 votes |
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); }
Example #12
Source File: CapabilitiesUtilsTest.java From joynr with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); Field objectMapperField = CapabilityUtils.class.getDeclaredField("objectMapper"); objectMapperField.setAccessible(true); objectMapperField.set(CapabilityUtils.class, objectMapper); }
Example #13
Source File: StaticCapabilitiesProvisioningTest.java From joynr with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); Field objectMapperField = CapabilityUtils.class.getDeclaredField("objectMapper"); objectMapperField.setAccessible(true); objectMapperField.set(CapabilityUtils.class, objectMapper); }
Example #14
Source File: DefaultJoynrRuntimeFactory.java From joynr with Apache License 2.0 | 5 votes |
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) { logger.error("Error parsing JSON.", e); } }
Example #15
Source File: ServersUtil.java From joynr with Apache License 2.0 | 5 votes |
private static String createJsonFor(String directoriesUrl) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); setObjectMapperOnCapabilitiesUtils(objectMapper); String channelId = "discoverydirectory_channelid"; String participantId = "capabilitiesdirectory_participantid"; GlobalDiscoveryEntry discoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalCapabilitiesDirectory.INTERFACE_NAME, participantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new ChannelAddress(directoriesUrl, channelId)); String accessParticipantId = "domainaccesscontroller_participantid"; GlobalDiscoveryEntry accessControlEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalDomainAccessController.INTERFACE_NAME, accessParticipantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new InProcessAddress()); List<DiscoveryEntry> entries = new ArrayList<>(); entries.add(discoveryEntry); entries.add(accessControlEntry); return objectMapper.writeValueAsString(entries); }
Example #16
Source File: JoynrEnd2EndTest.java From joynr with Apache License 2.0 | 5 votes |
protected static void provisionPermissiveAccessControlEntry(String domain, String interfaceName) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); List<MasterAccessControlEntry> provisionedAccessControlEntries = new ArrayList<MasterAccessControlEntry>(); String existingAccessControlEntriesJson = System.getProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES); if (existingAccessControlEntriesJson != null) { provisionedAccessControlEntries.addAll(Arrays.asList(objectMapper.readValue(existingAccessControlEntriesJson, MasterAccessControlEntry[].class))); } MasterAccessControlEntry newMasterAccessControlEntry = new MasterAccessControlEntry("*", domain, interfaceName, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[]{ TrustLevel.LOW }, "*", Permission.YES, new Permission[]{ Permission.YES }); provisionedAccessControlEntries.add(newMasterAccessControlEntry); String provisionedAccessControlEntriesAsJson = objectMapper.writeValueAsString(provisionedAccessControlEntries.toArray()); System.setProperty(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, provisionedAccessControlEntriesAsJson); }
Example #17
Source File: JsonJacksonCodec.java From redisson with Apache License 2.0 | 5 votes |
protected void initTypeInclusion(ObjectMapper mapObjectMapper) { TypeResolverBuilder<?> mapTyper = new DefaultTypeResolverBuilder(DefaultTyping.NON_FINAL) { public boolean useForType(JavaType t) { switch (_appliesFor) { case NON_CONCRETE_AND_ARRAYS: while (t.isArrayType()) { t = t.getContentType(); } // fall through case OBJECT_AND_NON_CONCRETE: return (t.getRawClass() == Object.class) || !t.isConcrete(); case NON_FINAL: while (t.isArrayType()) { t = t.getContentType(); } // to fix problem with wrong long to int conversion if (t.getRawClass() == Long.class) { return true; } if (t.getRawClass() == XMLGregorianCalendar.class) { return false; } return !t.isFinal(); // includes Object.class default: // case JAVA_LANG_OBJECT: return t.getRawClass() == Object.class; } } }; mapTyper.init(JsonTypeInfo.Id.CLASS, null); mapTyper.inclusion(JsonTypeInfo.As.PROPERTY); mapObjectMapper.setDefaultTyping(mapTyper); }
Example #18
Source File: RedisUtils.java From onetwo with Apache License 2.0 | 5 votes |
static public RedisSerializer<Object> typingJackson2RedisSerializer() { JsonMapper jsonMapper = JsonMapper.ignoreNull(); ObjectMapper mapper = jsonMapper.getObjectMapper(); mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY);//用这个配置,如果写入的对象是list,并且元素是复合对象时,会抛错:Current context not Object but Array // mapper.enableDefaultTyping(DefaultTyping.JAVA_LANG_OBJECT); RedisSerializer<Object> valueSerializer = new GenericJackson2JsonRedisSerializer(mapper); return valueSerializer; }
Example #19
Source File: JsonRedisTemplate.java From onetwo with Apache License 2.0 | 5 votes |
public JsonRedisTemplate() { JsonMapper jsonMapper = JsonMapper.ignoreNull(); ObjectMapper mapper = jsonMapper.getObjectMapper(); mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY);//用这个配置,如果写入的对象是list,并且元素是复合对象时,会抛错:Current context not Object but Array // mapper.enableDefaultTyping(DefaultTyping.JAVA_LANG_OBJECT); // RedisSerializer<String> keySerializer = new StringRedisSerializer(); RedisSerializer<Object> keySerializer = new GenericJackson2JsonRedisSerializer(mapper); RedisSerializer<Object> valueSerializer = new GenericJackson2JsonRedisSerializer(mapper); setKeySerializer(keySerializer); setValueSerializer(valueSerializer); setHashKeySerializer(keySerializer); setHashValueSerializer(valueSerializer); }
Example #20
Source File: JacksonXmlMapperTest.java From onetwo with Apache License 2.0 | 5 votes |
@Test public void testSerialWithTypeList() throws Exception{ JacksonXmlMapper jacksonXmlMapper = JacksonXmlMapper.ignoreNull(); ObjectMapper mapper = jacksonXmlMapper.getObjectMapper(); mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY); List<StoreDetailVo> list = Lists.newArrayList(); StoreDetailVo storeDetailVo = new StoreDetailVo(); storeDetailVo.setStoreId(1L); list.add(storeDetailVo); String s = mapper.writeValueAsString(list); System.out.println(s); }
Example #21
Source File: JsonMapperTest.java From onetwo with Apache License 2.0 | 5 votes |
@Test public void testSerialWithTypeList() throws Exception{ JsonMapper jsonMapper = JsonMapper.ignoreNull(); ObjectMapper mapper = jsonMapper.getObjectMapper(); mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY); List<StoreDetailVo> list = Lists.newArrayList(); StoreDetailVo storeDetailVo = new StoreDetailVo(); storeDetailVo.setStoreId(1L); list.add(storeDetailVo); String s = mapper.writeValueAsString(list); System.out.println(s); byte[] bytes = jsonMapper.toJsonBytes(list); List<StoreDetailVo> list2 = jsonMapper.fromJson(bytes, new TypeReference<List<StoreDetailVo>>() { }); assertThat(list2).isEqualTo(list2); String str1 = LangUtils.newString(bytes); System.out.println("json str1: " + str1); TestJsonData u1 = new TestJsonData(); u1.setCreate_time(new Timestamp(new Date().getTime())); u1.setUser_name("user_name"); String str = jsonMapper.toJson(u1); System.out.println("json str: " + str); bytes = jsonMapper.toJsonBytes(u1); String str2 = LangUtils.newString(bytes); System.out.println("json str2: " + str2); /*Map jsonstr = jsonMapper.fromJson(bytes, Map.class); System.out.println("json map: " + jsonstr);*/ }
Example #22
Source File: MarshallerService.java From dawnsci with Eclipse Public License 1.0 | 4 votes |
public RegisteredTypeResolverBuilder(DefaultTyping typing, MarshallerServiceClassRegistry registry) { super(typing); this.registry = registry; }
Example #23
Source File: ClassAliasTypeResolverBuilderTest.java From simple-spring-memcached with MIT License | 4 votes |
@Before public void setUp() { builder = new ClassAliasTypeResolverBuilder(DefaultTyping.NON_FINAL); }
Example #24
Source File: ClassAliasTypeResolverBuilder.java From simple-spring-memcached with MIT License | 4 votes |
public ClassAliasTypeResolverBuilder(final DefaultTyping typing) { super(typing); }
Example #25
Source File: JsonDataConverter.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 4 votes |
public JsonDataConverter() { this(new ObjectMapper()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); objectMapper.enableDefaultTyping(DefaultTyping.NON_FINAL); }
Example #26
Source File: SimpleFileBasedMessagePersister.java From joynr with Apache License 2.0 | 4 votes |
public SimpleFileBasedMessagePersister() { objectMapper = new ObjectMapper(); objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName"); }
Example #27
Source File: JsonMapper.java From onetwo with Apache License 2.0 | 4 votes |
public JsonMapper enableTyping(){ objectMapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY); return this; }
Example #28
Source File: TestMapMessage.java From sailfish-core with Apache License 2.0 | 4 votes |
@Test public void testMapMessageSerializationWithJson() throws IOException { MapMessage message = new MapMessage("namespace", "name"); message.addField("boolean", true); message.addField("boolean_array", Arrays.asList(new Boolean[] { true, false })); message.addField("byte", (byte) 1); message.addField("byte_array", Arrays.asList(new Byte[] { 2, 3, 4 })); message.addField("short", (short) 5); message.addField("short_array", Arrays.asList(new Short[] { 6, 7, 8 })); message.addField("int", 9); message.addField("int_array", Arrays.asList(new Integer[] { 10, 11, 12 })); message.addField("long", 13l); message.addField("long_array", Arrays.asList(new Long[] { 14l, 15l, 16l })); message.addField("float", 17.1f); message.addField("float_array", Arrays.asList(new Float[] { 18.1f, 19.1f, 20.1f })); message.addField("double", 21.1d); message.addField("double_array", Arrays.asList(new Double[] { 22.1d, 23.1d, 24.1d })); message.addField("bigdecimal", new BigDecimal("25.1")); message.addField("bigdecimal_array", Arrays.asList(new BigDecimal[] { new BigDecimal("26.1"), new BigDecimal("27.1"), new BigDecimal("28.1") })); message.addField("char", 'a'); message.addField("char_array", Arrays.asList(new Character[] { 'b', 'c', 'd' })); message.addField("string", "ef"); message.addField("string_array", Arrays.asList(new String[] { "gh", "jk", "lm" })); message.addField("localdatetime", DateTimeUtility.nowLocalDateTime()); message.addField("localdatetime_array", Arrays.asList(new LocalDateTime[] { DateTimeUtility.nowLocalDateTime(), DateTimeUtility.nowLocalDateTime(), DateTimeUtility.nowLocalDateTime() })); message.addField("localdate", DateTimeUtility.nowLocalDate()); message.addField("localdate_array", Arrays.asList(new LocalDate[] { DateTimeUtility.nowLocalDate(), DateTimeUtility.nowLocalDate(), DateTimeUtility.nowLocalDate() })); message.addField("localtime", DateTimeUtility.nowLocalTime()); message.addField("localtime_array", Arrays.asList(new LocalTime[] { DateTimeUtility.nowLocalTime(), DateTimeUtility.nowLocalTime(), DateTimeUtility.nowLocalTime() })); MsgMetaData metaData = message.getMetaData(); metaData.setDictionaryURI(SailfishURI.unsafeParse("plugin.dictionary")); metaData.setFromService("fromService"); metaData.setToService("toService"); metaData.setRawMessage(new byte[] { 1, 2, 3, 4, 5 }); metaData.setServiceInfo(new ServiceInfo("id", new ServiceName("env", "serviceName"))); MapMessage subMessage = message.cloneMessage(); message.addField("message", subMessage); message.addField("message_array", Arrays.asList(new MapMessage[] { subMessage, subMessage })); ObjectMapper objectMapper = new ObjectMapper().enableDefaultTyping(DefaultTyping.NON_FINAL) .registerModule(new JavaTimeModule()); ObjectReader reader = objectMapper.reader(IMessage.class); ObjectWriter writer = objectMapper.writer(); String json = writer.writeValueAsString(message); IMessage message2 = reader.readValue(json); Assert.assertEquals(message, message2); }
Example #29
Source File: GenericMsgpackRedisSerializer.java From Ffast-Java with MIT License | 4 votes |
public GenericMsgpackRedisSerializer() { this.mapper = new ObjectMapper(new MessagePackFactory()); this.mapper.registerModule((new SimpleModule()).addSerializer(new GenericMsgpackRedisSerializer.NullValueSerializer(null))); this.mapper.enableDefaultTyping(DefaultTyping.NON_FINAL, As.PROPERTY); }