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:com.okta.sdk.models.links.LinksUnionDeserializer.java
@Override public LinksUnion deserialize(JsonParser parser, DeserializationContext context) throws IOException { ObjectMapper mapper = (ObjectMapper) parser.getCodec(); JsonNode root = mapper.readTree(parser); if (root.isArray()) { return mapper.convertValue(root, Links.class); } else if (root.isObject()) { return mapper.convertValue(root, Link.class); }// w ww .ja v a2s. c o m return null; }
From source file:od.providers.api.EventController.java
@RequestMapping(value = "/api/proxy/event", method = RequestMethod.POST) public JsonNode postEvent(@RequestBody ObjectNode object) throws Exception { ObjectMapper mapper = new ObjectMapper(); ProviderOptions options = mapper.convertValue(object.get("options"), ProviderOptions.class); EventProvider eventProvider = providerService .getEventProvider(mongoTenantRepository.findOne(options.getTenantId())); return eventProvider.postEvent(object.get("caliperEvent"), options); }
From source file:org.springframework.security.jackson2.UserDeserializer.java
/** * This method will create {@link User} object. It will ensure successful object creation even if password key is null in * serialized json, because credentials may be removed from the {@link User} by invoking {@link User#eraseCredentials()}. * In that case there won't be any password key in serialized json. *//*from w w w .j av a2 s . c o m*/ @Override public User deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); JsonNode jsonNode = mapper.readTree(jp); Set<GrantedAuthority> authorities = mapper.convertValue(jsonNode.get("authorities"), new TypeReference<Set<SimpleGrantedAuthority>>() { }); return new User(readJsonNode(jsonNode, "username").asText(), readJsonNode(jsonNode, "password").asText(), readJsonNode(jsonNode, "enabled").asBoolean(), readJsonNode(jsonNode, "accountNonExpired").asBoolean(), readJsonNode(jsonNode, "credentialsNonExpired").asBoolean(), readJsonNode(jsonNode, "accountNonLocked").asBoolean(), authorities); }
From source file:com.athena.dolly.cloudant.CloudantEventListener.java
public List<SFile> waitForMeta() { List<SFile> result = new ArrayList<SFile>(); JsonNode a_samsung_file = (JsonNode) connSeq.find(JsonNode.class, "a_samsung_file"); if (a_samsung_file != null) { System.out.println("Since: " + a_samsung_file.get("seq").textValue()); cmd = new ChangesCommand.Builder().since(a_samsung_file.get("seq").textValue()).includeDocs(true) .build();//from ww w. j a v a2s. c o m } else { cmd = new ChangesCommand.Builder().includeDocs(true).build(); } // Event Process ChangesFeed feed = conn.changesFeed(cmd); while (feed.isAlive()) { DocumentChange change = null; try { System.out.println("Waiting..."); change = feed.next(); // change = feed.next(5, TimeUnit.SECONDS); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (change != null) { DocumentChange newChange = null; do { String docId = change.getId(); JsonNode changedDoc = change.getDocAsNode(); ObjectMapper om = new ObjectMapper(); SFile aFile = om.convertValue(changedDoc, SFile.class); result.add(aFile); System.out.println(changedDoc + ", seq=" + change.getStringSequence()); try { newChange = feed.poll(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } while (newChange != null); // ? ? seq if (a_samsung_file == null) { ObjectMapper om = new ObjectMapper(); a_samsung_file = om.createObjectNode(); ((ObjectNode) a_samsung_file).put("_id", "a_samsung_file"); ((ObjectNode) a_samsung_file).put("seq", change.getStringSequence()); connSeq.create(a_samsung_file); } else { ((ObjectNode) a_samsung_file).put("seq", change.getStringSequence()); connSeq.update(a_samsung_file); } } } return result; }
From source file:org.lappsgrid.eval.AnnotationEvaluator.java
private String setEvalConfig(String data, EvaluationConfig evalConfig) { Data<Object> result = Serializer.parse(data, Data.class); Object payload = result.getPayload(); Container container = new Container((Map) payload); ObjectMapper mapper = new ObjectMapper(); Map evalConfigMap = mapper.convertValue(evalConfig, Map.class); container.setMetadata(EVALUATION_CONFIGURATION_NAME, evalConfigMap); result.setPayload(container);/*from w ww . j a v a 2s . c o m*/ return Serializer.toJson(result); }
From source file:org.wso2.carbon.bpmn.core.types.datatypes.json.api.JsonNodeObject.java
/** * Function to evaluate jsonpath over JsonNodeObject * @param jsonPathStr jsonpath/*from w w w .j a v a 2 s .c om*/ * @return returns the evaluation result. The returned Object can be a * com.fasterxml.jackson.databind.JsonNode (in case the result is json object) * com.fasterxml.jackson.databind.node.ArrayNode (in case the result is json array) * Or main primitive data types (String, Integer, Byte, Character, Short, Long, Float, Double, Boolean) * This function returns new Object representing the evaluation results, no a reference to a node * @throws IOException * @throws BPMNJsonException is thrown if the the resulting data type cannot be identified */ public Object jsonPath(String jsonPathStr) throws IOException, BPMNJsonException { ObjectMapper mapper = new ObjectMapper(); Map map = mapper.convertValue(jsonNode, Map.class); Object result = JsonPath.read(map, jsonPathStr); JsonBuilder builder = new JsonBuilder(mapper); if (result instanceof Map) { //If the result is a Map, then it should be a json object return builder.createJsonNodeFromMap((Map<String, Object>) result); } else if (result instanceof List) { //when result is a list, then it should be a json array return builder.createJsonArrayFromMap((List<Object>) result); } else if (result instanceof String || result instanceof Integer || result instanceof Byte || result instanceof Character || result instanceof Short || result instanceof Long || result instanceof Float || result instanceof Double || result instanceof Boolean) { //If result is primitive data type, then return it as it is return result; } else { //Un-filtered data type, considered as unknown types throw new BPMNJsonException("Unknown type data type: " + result.getClass().getName() + " resulted while evaluating json path"); } }
From source file:inti.ws.spring.resource.index.IndexConfig.java
@Override public Map<String, FilteredWebResource> instanceWebResources(ObjectMapper mapper, JsonNode node) throws Exception { return parseIndex(mapper.convertValue(node, IndexBean.class)); }
From source file:com.yahoo.elide.jsonapi.serialization.DataDeserializer.java
@Override public Data<Resource> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); ObjectMapper mapper = new MappingJsonFactory().getCodec(); if (node.isArray()) { List<Resource> resources = new ArrayList<>(); for (JsonNode n : node) { Resource r = mapper.convertValue(n, Resource.class); resources.add(r);//www.j a va2s . c om } return new Data<>(resources); } Resource resource = mapper.convertValue(node, Resource.class); return new Data<>(resource); }
From source file:org.lappsgrid.eval.AnnotationEvaluator.java
@Override public String execute(String input) { //input = setDefaultEvalConfig(input); //for testing example // logger.info("AnnotationEvaluator started... with input size: {}", input.length()); System.out.println("AnnotationEvaluator started... with input size: " + input.length()); String eval_result = ""; try {/*from w w w.jav a 2 s. c o m*/ Data<Object> result = Serializer.parse(input, Data.class); Object payload = result.getPayload(); Container container = new Container((Map) payload); Map<String, String> evalConfigMap = (Map<String, String>) container .getMetadata(EVALUATION_CONFIGURATION_NAME); ObjectMapper mapper = new ObjectMapper(); EvaluationConfig evalConfig = mapper.convertValue(evalConfigMap, EvaluationConfig.class); if (evalConfig == null) { evalConfig = new EvaluationConfig(); // use default } eval_result = evaluate(container, evalConfig); } catch (Exception e) { e.printStackTrace(); } System.out.println("AnnotationEvaluator ended with output size: " + eval_result.length()); return eval_result; }
From source file:com.servioticy.datamodel.serviceobject.SO.java
public void setStreams(LinkedHashMap<String, SOStream> streams, ObjectMapper mapper) { this.streams = streams; this.streamsRaw = (LinkedHashMap<String, Object>) mapper.convertValue(streams, new TypeReference<Map<String, Object>>() { });// ww w . j a v a 2 s. c o m }