List of usage examples for com.fasterxml.jackson.databind ObjectMapper convertValue
@SuppressWarnings("unchecked") public <T> T convertValue(Object fromValue, JavaType toValueType) throws IllegalArgumentException
From source file:inti.ws.spring.resource.mail.MailsConfig.java
@Override public Map<String, MailResource> instanceWebResources(ObjectMapper mapper, JsonNode node) throws Exception { Iterator<Entry<String, JsonNode>> fields = node.fields(); Entry<String, JsonNode> field; Map<String, MailResource> resources = new HashMap<>(); while (fields.hasNext()) { field = fields.next();/*from ww w .ja v a 2 s. c om*/ resources.put(field.getKey(), parseMail(mapper.convertValue(field.getValue(), MailBean.class))); } return resources; }
From source file:com.amazon.speech.json.SupportedInterfacesDeserializer.java
@Override public SupportedInterfaces deserialize(JsonParser parser, DeserializationContext context) throws IOException { ObjectMapper underlyingMapper = ((ObjectMapper) parser.getCodec()); JsonNode messageNode = parser.readValueAsTree(); SupportedInterfaces.Builder supportedInterfacesBuilder = SupportedInterfaces.builder(); for (SerializedInterface interfaceName : SerializedInterface.values()) { if (messageNode.has(interfaceName.name())) { Interface supportedInterface = underlyingMapper.convertValue(messageNode.get(interfaceName.name()), interfaceName.getInterfaceClass()); supportedInterfacesBuilder.addSupportedInterface(supportedInterface); }/*from w ww . j a va2s . c o m*/ } return supportedInterfacesBuilder.build(); }
From source file:com.almende.eve.protocol.jsonrpc.formats.JSONRequest.java
/** * Gets the param.// w w w . j a v a2 s . com * * @param name * the name * @return the param */ public Object getParam(final String name) { final ObjectMapper mapper = JOM.getInstance(); if (params.has(name)) { return mapper.convertValue(params.get(name), Object.class); } return null; }
From source file:com.almende.eve.rpc.jsonrpc.JSONRequest.java
/** * Gets the param.//from ww w.jav a 2 s. c om * * @param name the name * @return the param */ public Object getParam(final String name) { final ObjectMapper mapper = JOM.getInstance(); final ObjectNode params = req.with(PARAMS); if (params.has(name)) { return mapper.convertValue(params.get(name), Object.class); } return null; }
From source file:ai.general.net.RemoteMethodTest.java
/** * Tests handling of call errors.//from ww w. ja va2 s . com */ @Test public void callError() { final String kHomePath = "/remote_method/error"; final String kMethod = "/error"; final String kUserAccount = "error_user"; Directory directory = Directory.Instance; Assert.assertTrue(directory.createPath(kHomePath + kMethod)); try { Assert.assertTrue(directory.addHandler(kHomePath + kMethod, new MethodHandler(kMethod, false, null, getClass().getDeclaredMethod("error", String.class, TestBean.class)))); } catch (NoSuchMethodException e) { Assert.fail(e.toString()); } Uri uri = new Uri("ws", kHostname, "/remote_method_test"); WampConnectionTest.TestSender client_sender = new WampConnectionTest.TestSender(); WampConnectionTest.TestSender server_sender = new WampConnectionTest.TestSender(); WampConnection client = new WampConnection(uri, kUserAccount, "", client_sender); WampConnection server = new WampConnection(uri, kUserAccount, kHomePath, server_sender); server.welcome("test-session-" + kUserAccount); client.process(server_sender.getOutput()); RemoteMethod<TestBean> remote_method = new RemoteMethod<TestBean>(client, kMethod, TestBean.class); CallProcessor processor = new CallProcessor(client, client_sender, server, server_sender); TestBean bean = new TestBean(1010, 0.1, "details"); CallThread call_thread = new CallThread(remote_method, true, "remote method test", bean); processor.start(); call_thread.start(); synchronized (call_thread) { while (call_thread.isAlive()) { try { call_thread.wait(); } catch (InterruptedException e) { } } } synchronized (processor) { while (processor.isAlive()) { try { processor.wait(); } catch (InterruptedException e) { } } } RemoteMethodCall<TestBean> method_call = call_thread.getMethodCall(); Assert.assertNotNull(method_call); assertThat(method_call.getState(), is(RemoteMethodCall.State.Completed)); Assert.assertFalse(method_call.isSuccessful()); assertThat(method_call.getErrorUri().toString(), is("wamp://error_user@general.ai" + kMethod + "#logic_error")); assertThat(method_call.getErrorDescription(), is("remote method test")); ObjectMapper mapper = new ObjectMapper(); assertThat(mapper.convertValue(method_call.getErrorDetails(), TestBean.class), is(bean)); if (call_thread.getThreadCompletionTimeMillis() < processor.getThreadCompletionTimeMillis()) { Assert.fail("Call thread completion time: " + call_thread.getThreadCompletionTimeMillis() + ", Processor thread completion time: " + processor.getThreadCompletionTimeMillis()); } client.close(); server.close(); }
From source file:com.netflix.spinnaker.halyard.config.model.v1.node.Node.java
public <T> T cloneNode(Class<T> tClass) { ObjectMapper mapper = new ObjectMapper(); return mapper.convertValue(mapper.convertValue(this, Map.class), tClass); }
From source file:io.druid.segment.realtime.plumber.RealtimePlumberSchoolTest.java
@Before public void setUp() throws Exception { final File tmpDir = Files.createTempDir(); tmpDir.deleteOnExit();/* w w w.j a va 2s . c o m*/ ObjectMapper jsonMapper = new DefaultObjectMapper(); schema = new DataSchema("test", jsonMapper.convertValue( new StringInputRowParser(new JSONParseSpec(new TimestampSpec("timestamp", "auto", null), new DimensionsSpec(null, null, null))), Map.class), new AggregatorFactory[] { new CountAggregatorFactory("rows") }, new UniformGranularitySpec(Granularity.HOUR, QueryGranularity.NONE, null), jsonMapper); schema2 = new DataSchema("test", jsonMapper.convertValue( new StringInputRowParser(new JSONParseSpec(new TimestampSpec("timestamp", "auto", null), new DimensionsSpec(null, null, null))), Map.class), new AggregatorFactory[] { new CountAggregatorFactory("rows") }, new UniformGranularitySpec(Granularity.YEAR, QueryGranularity.NONE, null), jsonMapper); announcer = EasyMock.createMock(DataSegmentAnnouncer.class); announcer.announceSegment(EasyMock.<DataSegment>anyObject()); EasyMock.expectLastCall().anyTimes(); segmentPublisher = EasyMock.createNiceMock(SegmentPublisher.class); dataSegmentPusher = EasyMock.createNiceMock(DataSegmentPusher.class); serverView = EasyMock.createMock(FilteredServerView.class); serverView.registerSegmentCallback(EasyMock.<Executor>anyObject(), EasyMock.<ServerView.SegmentCallback>anyObject(), EasyMock.<Predicate<DataSegment>>anyObject()); EasyMock.expectLastCall().anyTimes(); emitter = EasyMock.createMock(ServiceEmitter.class); EasyMock.replay(announcer, segmentPublisher, dataSegmentPusher, serverView, emitter); tuningConfig = new RealtimeTuningConfig(1, null, null, null, new IntervalStartVersioningPolicy(), rejectionPolicy, null, null, null, null, null, null, null); realtimePlumberSchool = new RealtimePlumberSchool(emitter, new DefaultQueryRunnerFactoryConglomerate( Maps.<Class<? extends Query>, QueryRunnerFactory>newHashMap()), dataSegmentPusher, announcer, segmentPublisher, serverView, MoreExecutors.sameThreadExecutor()); metrics = new FireDepartmentMetrics(); plumber = (RealtimePlumber) realtimePlumberSchool.findPlumber(schema, tuningConfig, metrics); }
From source file:inti.ws.spring.resource.template.TemplatesConfig.java
@Override public Map<String, TemplateResource> instanceWebResources(ObjectMapper mapper, JsonNode node) throws Exception { Iterator<Entry<String, JsonNode>> fields = node.fields(); Entry<String, JsonNode> field; Map<String, TemplateResource> resources = new HashMap<>(); while (fields.hasNext()) { field = fields.next();/*from w w w . j a v a 2s .com*/ resources.put(field.getKey(), parseTemplate(field.getKey(), mapper.convertValue(field.getValue(), TemplateBean.class))); } return resources; }
From source file:com.chboeh.lightspeed.demo.util.ShuffleTest.java
@Before public void setUp() { try {/*from ww w . j a v a2s.c o m*/ //question.json file data is a project resource InputStream is = QuizDemo.class.getResourceAsStream("/questions.json"); byte[] jsonData = IOUtils.toByteArray(is); ObjectMapper objectMapper = new ObjectMapper(); //convert json string to object Root root = objectMapper.readValue(jsonData, Root.class); Quiz quiz = root.getQuiz(); questions = new ArrayList(quiz.getQuestions().size()); for (Map<String, Object> item : quiz.getQuestions()) { //Parse questions and set the correct answer option Question question = objectMapper.convertValue(item, Question.class); question.setCorrectAnswer(); questions.add(question); } } catch (IOException ex) { System.out.println(ex); } }
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.ElasticsearchIndexUtils.java
/** Returns either a specific type name, or "_default_" if auto types are used * @param bucket//from w w w . j a va2s .c om * @return */ public static String getTypeKey(final DataBucketBean bucket, final ObjectMapper mapper) { return Optional.ofNullable(bucket.data_schema()).map(DataSchemaBean::search_index_schema) .filter(s -> Optional.ofNullable(s.enabled()).orElse(true)) .map(DataSchemaBean.SearchIndexSchemaBean::technology_override_schema) .map(t -> BeanTemplateUtils .from(mapper.convertValue(t, JsonNode.class), SearchIndexSchemaDefaultBean.class).get()) .<String>map(cfg -> { return Patterns.match(cfg.collide_policy()).<String>andReturn() .when(cp -> SearchIndexSchemaDefaultBean.CollidePolicy.error == cp, __ -> Optional.ofNullable(cfg.type_name_or_prefix()) .orElse(ElasticsearchIndexServiceConfigBean.DEFAULT_FIXED_TYPE_NAME)) // (ie falls through to default below) .otherwise(__ -> null); }).orElse("_default_"); // (the default - "auto type") }