List of usage examples for com.fasterxml.jackson.databind.module SimpleModule addDeserializer
public <T> SimpleModule addDeserializer(Class<T> type, JsonDeserializer<? extends T> deser)
From source file:net.solarnetwork.util.ObjectMapperFactoryBean.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private void registerStdDeserializer(SimpleModule module, StdDeserializer stdDeserializer) { Class deserType = stdDeserializer.handledType(); module.addDeserializer(deserType, stdDeserializer); }
From source file:org.springframework.yarn.integration.support.Jackson2ObjectMapperFactoryBean.java
@SuppressWarnings("unchecked") private <T> void addDeserializers(SimpleModule module) { for (Class<?> type : this.deserializers.keySet()) { module.addDeserializer((Class<T>) type, (JsonDeserializer<? extends T>) this.deserializers.get(type)); }/*w w w . j a v a 2 s.c o m*/ }
From source file:org.venice.beachfront.bfapi.services.OAuthServiceTests.java
@Before public void setup() { MockitoAnnotations.initMocks(this); SimpleModule module = new SimpleModule(); module.addDeserializer(AbstractStringList.class, new AbstractStringList.Deserializer()); this.objectMapper.registerModule(module); ReflectionTestUtils.setField(this.oauthService, "domain", "test.localdomain"); ReflectionTestUtils.setField(this.oauthService, "oauthTokenUrl", this.oauthTokenUrl); ReflectionTestUtils.setField(this.oauthService, "redirectUrl", this.redirectUrl); ReflectionTestUtils.setField(this.oauthService, "oauthProfileUrl", this.oauthProfileUrl); ReflectionTestUtils.setField(this.oauthService, "oauthClientId", this.oauthClientId); ReflectionTestUtils.setField(this.oauthService, "oauthClientSecret", this.oauthClientSecret); ReflectionTestUtils.setField(this.oauthService, "oauthResponseLogOnError", false); }
From source file:org.wisdom.monitor.extensions.jcr.script.JcrScriptExecutorExtension.java
@Route(method = HttpMethod.GET, uri = "") public Result index() throws Exception { Session session = jcrRepository.getSession(); Optional<String> currentMigrationWorkspaceOptional = Arrays .asList(session.getWorkspace().getAccessibleWorkspaceNames()).stream() .filter(name -> name.startsWith(JCR_MIGRATION_PREFIX)).findFirst(); String workspace = ""; String script = ""; List<Event> events = new ArrayList<>(); if (currentMigrationWorkspaceOptional.isPresent()) { workspace = currentMigrationWorkspaceOptional.get(); Node rootNode = session.getRepository().login(workspace).getRootNode(); if (rootNode.hasNode("jcr:migrations")) { Node migrationNode = rootNode.getNode("jcr:migrations").getNode(workspace); script = migrationNode.getProperty("script").getString(); ObjectMapper mapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addDeserializer(Event.class, new JcrEventDeserializer()); mapper.registerModule(module); events = mapper.readValue(migrationNode.getProperty("events").getString(), mapper.getTypeFactory().constructCollectionType(List.class, Event.class)); }//from w w w.j a va 2 s . c om } return ok(render(scriptTemplate, "script", script, "workspace", workspace, "events", events, "eventFormatter", EVENT_FORMATTER)); }
From source file:gaffer.serialisation.json.hyperloglogplus.HyperLogLogPlusJsonSerialisationTest.java
@Before public void before() { mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); final SimpleModule module = new SimpleModule( HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SERIALISER_MODULE_NAME, new Version(1, 0, 0, null)); module.addSerializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonSerialiser()); module.addDeserializer(HyperLogLogPlus.class, new HyperLogLogPlusJsonDeserialiser()); mapper.registerModule(module);/*from w ww . ja va 2 s.c o m*/ }
From source file:com.intelligentsia.dowsers.entity.reference.ReferenceTest.java
@Test public void testSerialization() throws JsonParseException, JsonMappingException, IOException { final ObjectMapper mapper = JacksonSerializer.getMapper(); final SimpleModule module = new SimpleModule(); module.addSerializer(new ReferenceSerializer()); module.addDeserializer(Reference.class, new ReferenceDeSerializer()); mapper.registerModule(module);/* w ww . j a va 2 s.c o m*/ final StringWriter writer = new StringWriter(); final Reference reference = Reference.parseString( "urn:dowsers:com.intelligentsia.dowsers.entity.model.Person:identity#4c8b03dd-908a-4cad-8d48-3c7277d44ac9"); mapper.writeValue(writer, reference); final String result = writer.toString(); final Reference reference2 = mapper.readValue(new StringReader(result), Reference.class); assertNotNull(reference2); assertEquals(reference, reference2); }
From source file:io.seldon.api.state.PredictionAlgorithmStore.java
@Override public void configUpdated(String client, String configKey, String configValue) { SimpleModule module = new SimpleModule("PredictionStrategyDeserializerModule"); module.addDeserializer(Strategy.class, new PredictionStrategyDeserializer()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module);//ww w .ja v a 2 s .c o m if (configKey.equals(ALG_KEY)) { logger.info("Received new algorithm config for " + client + ": " + configValue); try { Strategy configStrategy = mapper.readValue(configValue, Strategy.class); if (configStrategy instanceof AlgorithmConfig) { List<PredictionAlgorithmStrategy> strategies = new ArrayList<>(); AlgorithmConfig config = (AlgorithmConfig) configStrategy; for (Algorithm algorithm : config.algorithms) { PredictionAlgorithmStrategy strategy = toAlgorithmStrategy(algorithm); strategies.add(strategy); } List<FeatureTransformerStrategy> featureTransformerStrategies = new ArrayList<>(); if (config.transformers != null) for (Transformer transformer : config.transformers) { FeatureTransformerStrategy strategy = toFeatureTransformerStrategy(transformer); featureTransformerStrategies.add(strategy); } predictionStore.put(client, new SimplePredictionStrategy(PredictionStrategy.DEFAULT_NAME, Collections.unmodifiableList(featureTransformerStrategies), Collections.unmodifiableList(strategies))); logger.info("Successfully added new algorithm config for " + client); } else if (configStrategy instanceof TestConfig) { TestConfig config = (TestConfig) configStrategy; //TestConfig config = mapper.readValue(configValue, TestConfig.class); List<VariationPredictionStrategy.Variation> variations = new ArrayList<>(); for (TestVariation var : config.variations) { List<PredictionAlgorithmStrategy> strategies = new ArrayList<>(); for (Algorithm alg : var.config.algorithms) { PredictionAlgorithmStrategy strategy = toAlgorithmStrategy(alg); strategies.add(strategy); } List<FeatureTransformerStrategy> featureTransformerStrategies = new ArrayList<>(); if (var.config.transformers != null) for (Transformer transformer : var.config.transformers) { FeatureTransformerStrategy strategy = toFeatureTransformerStrategy(transformer); featureTransformerStrategies.add(strategy); } //Need to add combiner here variations .add(new VariationPredictionStrategy.Variation( new SimplePredictionStrategy(var.label, Collections.unmodifiableList(featureTransformerStrategies), Collections.unmodifiableList(strategies)), new BigDecimal(var.ratio))); } predictionStore.put(client, VariationPredictionStrategy.build(variations)); logger.info("Succesfully added " + variations.size() + " variation test for " + client); } else { logger.error("Unknown type for algorithm config"); } } catch (IOException | BeansException e) { logger.error("Couldn't update algorithms for client " + client, e); } } }
From source file:org.craftercms.social.util.serialization.UGCObjectMapper.java
protected void registerSerializationModule() { SimpleModule module = new SimpleModule("UGCSerializationModule", new Version(1, 0, 0, null, null, null)); for (JsonSerializer ser : serializerList) { module.addSerializer(ser);/*from w ww.j a v a 2 s . c o m*/ } for (Class key : deserializerMap.keySet()) { JsonDeserializer deser = deserializerMap.get(key); module.addDeserializer(key, deser); } registerModule(module); }
From source file:com.spotify.ffwd.filter.FilterDeserializerTest.java
@Before public void setup() { final SimpleModule m = new SimpleModule(); final Map<String, FilterDeserializer.PartialDeserializer> filters = new HashMap<>(); filters.put("and", new AndFilter.Deserializer()); filters.put("or", new OrFilter.Deserializer()); filters.put("key", new MatchKey.Deserializer()); filters.put("not", new NotFilter.Deserializer()); m.addDeserializer(Filter.class, new FilterDeserializer(filters)); mapper = new ObjectMapper(); mapper.registerModule(m);/*from w w w. ja v a 2s .c om*/ }
From source file:com.google.code.pathlet.web.json.JsonRequestProcessor.java
public JsonRequestProcessor(Map<String, String> parameterPropertyMap, Map<Class<?>, JsonDeserializer<?>> deserializerMap) { this.objectMapper = new ObjectMapper(); SimpleModule testModule = new SimpleModule("MyModule"); if (deserializerMap != null && deserializerMap.size() > 0) { for (Map.Entry<Class<?>, JsonDeserializer<?>> entry : deserializerMap.entrySet()) { Class type = entry.getKey(); JsonDeserializer serializer = entry.getValue(); testModule.addDeserializer(type, serializer); }//from ww w . j a va 2 s .c o m objectMapper.registerModule(testModule); } this.parameterPropertyMap = parameterPropertyMap; }