List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:org.agorava.facebook.jackson.TagListDeserializer.java
@SuppressWarnings("unchecked") @Override/*from ww w.j av a 2 s. c o m*/ public List<Tag> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = BeanResolver.getInstance().resolve(ObjectMapper.class); jp.setCodec(mapper); if (jp.hasCurrentToken()) { JsonNode dataNode = (JsonNode) jp.readValueAs(JsonNode.class).get("data"); return (List<Tag>) mapper.reader(new TypeReference<List<Tag>>() { }).readValue(dataNode); } return null; }
From source file:com.networknt.light.rule.form.ImpFormRule.java
public boolean execute(Object... objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>) objects[0]; Map<String, Object> data = (Map<String, Object>) inputMap.get("data"); Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload"); Map<String, Object> user = (Map<String, Object>) payload.get("user"); String error = null;/*from w w w.ja v a 2 s.c o m*/ String host = (String) user.get("host"); Map<String, Object> dataMap = mapper.readValue((String) data.get("content"), new TypeReference<HashMap<String, Object>>() { }); String formId = (String) dataMap.get("formId"); if (host != null) { if (!host.equals(data.get("host"))) { error = "User can only import form from host: " + host; inputMap.put("responseCode", 403); } else { if (!formId.contains(host)) { // you are not allowed to add form as it is not owned by the host. error = "form id doesn't contain host: " + host; inputMap.put("responseCode", 403); } else { // Won't check if form exists or not here. Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("host", host); eventData.put("formId", formId); eventData.put("action", dataMap.get("action")); eventData.put("schema", dataMap.get("schema")); eventData.put("form", dataMap.get("form")); if (dataMap.get("modelData") != null) eventData.put("modelData", dataMap.get("modelData")); eventData.put("createDate", new java.util.Date()); eventData.put("createUserId", user.get("userId")); } } } else { // This is owner to import form, notice no host is passed in. Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("formId", formId); eventData.put("action", dataMap.get("action")); eventData.put("schema", dataMap.get("schema")); eventData.put("form", dataMap.get("form")); if (dataMap.get("modelData") != null) eventData.put("modelData", dataMap.get("modelData")); eventData.put("createDate", new java.util.Date()); eventData.put("createUserId", user.get("userId")); } if (error != null) { inputMap.put("error", error); return false; } else { return true; } }
From source file:my.custom.transformer.TweetTransformer.java
@Transformer(inputChannel = "input", outputChannel = "output") public List<BaseModel> transform(String payload) { try {/*from w ww . ja v a 2 s. com*/ return writer .flush(modelHandler.process(mapper.readValue(payload, new TypeReference<Map<String, Object>>() { }))); } catch (IOException e) { throw new MessageTransformationException("Unable to transform tweet: " + e.getMessage(), e); } }
From source file:com.github.nmorel.gwtjackson.jackson.advanced.jsontype.JsonTypeWithGenericsJacksonTest.java
@Test public void testWrapperWithField() { JsonTypeWithGenericsTester.INSTANCE/* w w w . j a va 2 s . c o m*/ .testWrapperWithField(createWriter(new TypeReference<ContainerWithField<Animal>>() { })); }
From source file:com.github.leonardoxh.temporeal.app.utils.JsonUtils.java
/** * Este metodo tambem transforma qualquer json valido * em algum dos nossos models porem este retorna uma lista * @param json um json valido para transformarmos em objeto * @param clazz a classe que esperamos/*from w w w .j a v a 2s . c o m*/ * @param <T> tipo da classe para retorno * @return uma lista com os nossos models (nunca null) */ public static <T extends Model> List<T> listFromJson(String json, Class<T> clazz) { try { return OBJECT_MAPPER.readValue(json, new TypeReference<List<T>>() { }); } catch (Exception e) { e.printStackTrace(); } return Collections.emptyList(); }
From source file:com.opensearchserver.hadse.cluster.ClusterCatalog.java
public final static void init(int port) throws JsonGenerationException, JsonMappingException, URISyntaxException, IOException { List<String> addrList = new ArrayList<String>(); NetworksUtils.collectExternalIpAdresses(addrList); localAddresses.clear();/*from w ww . j av a2 s .c om*/ if (addrList != null) for (String addr : addrList) localAddresses.add(addr + ":" + port); List<NodeItem> nodeItems = null; if (clusterFile.exists()) { try { nodeItems = JsonUtils.mapper.readValue(clusterFile, new TypeReference<ArrayList<NodeItem>>() { }); } catch (Throwable t) { throw new RuntimeException(t); } if (nodeItems != null) for (NodeItem nodeItem : nodeItems) { nodes.add(nodeItem); for (String addr : nodeItem.getAddresses()) addressMap.put(addr, nodeItem); } } add(localAddresses); }
From source file:retsys.client.json.JsonHelper.java
public Map<String, Object>[] getJsonMapArray(String jsonString) { Map<String, Object>[] jsonMap = null;//new HashMap[]<String,Object>(); try {/*w w w. j av a2 s . co m*/ jsonMap = mapper.readValue(jsonString, new TypeReference<HashMap<String, Object>[]>() { }); } catch (Exception e) { e.printStackTrace(); } return jsonMap; }
From source file:com.github.nmorel.gwtjackson.jackson.annotations.JsonRawValueJacksonTest.java
@Test public void testNullStringGetter() { JsonRawValueTester.INSTANCE.testNullStringGetter(createMapper(new TypeReference<ClassGetter<String>>() { })); }
From source file:com.orange.clara.cloud.truststore.CertificateJsonDeserializer.java
@Override public List<Certificate> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); if (jp.getCurrentToken().equals(JsonToken.START_ARRAY)) { final List<String> certificates = mapper.readValue(jp, new TypeReference<List<String>>() { });/*from w w w . j a v a2s . co m*/ final List<Certificate> collect = certificates.stream().map(e -> CertificateFactory.newInstance(e)) .collect(Collectors.toList()); return collect; } else { //consume this stream mapper.readTree(jp); return new ArrayList<Certificate>(); } }
From source file:org.killbill.billing.plugin.meter.timeline.shutdown.StartTimesMapper.java
@Override public StartTimes map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException { try {/*from w ww . ja va 2 s. com*/ return new StartTimes(DateTimeUtils.dateTimeFromUnixSeconds(r.getInt("time_inserted")), (Map<Integer, Map<Integer, DateTime>>) mapper.readValue( r.getBlob("start_times").getBinaryStream(), new TypeReference<Map<Integer, Map<Integer, DateTime>>>() { })); } catch (IOException e) { throw new IllegalStateException(String.format("Could not decode the StartTimes map"), e); } }