List of usage examples for com.fasterxml.jackson.databind ObjectMapper readValue
@SuppressWarnings("unchecked") public <T> T readValue(byte[] src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
From source file:org.bigloupe.web.monitor.util.JSONUtil.java
public static Object readJson(String json, TypeReference type) throws IOException { ObjectMapper om = new ObjectMapper(); om.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); // not currently setting successors, only successorNames return om.readValue(json, type); }
From source file:com.chiralbehaviors.CoRE.kernel.KernelUtil.java
private static RehydratedWorkspace readKernel(InputStream is) throws IOException, JsonParseException, JsonMappingException { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new CoREModule()); RehydratedWorkspace workspace = mapper.readValue(is, RehydratedWorkspace.class); return workspace; }
From source file:org.fede.util.Util.java
private static JSONSeries readConsultatioSeries(InputStream is, ObjectMapper om) throws IOException { List<ConsultatioDataPoint> data = om.readValue(is, new TypeReference<List<ConsultatioDataPoint>>() { });/* w w w. j ava 2 s . c o m*/ Map<Pair<Integer, Integer>, List<BigDecimal>> groups = new HashMap<>(); List<JSONDataPoint> points = new ArrayList<>(data.size()); Calendar cal = Calendar.getInstance(); for (ConsultatioDataPoint c : data) { cal.setTime(c.getDate()); final Pair<Integer, Integer> key = new Pair<>(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1); List<BigDecimal> values = groups.get(key); if (values == null) { values = new ArrayList<>(32); groups.put(key, values); } values.add(c.getValue().movePointLeft(2)); } for (Map.Entry<Pair<Integer, Integer>, List<BigDecimal>> entry : groups.entrySet()) { points.add(new JSONDataPoint(entry.getKey().getFirst(), entry.getKey().getSecond(), avg(entry.getValue()))); } return new JSONSeries("ARS", points, "LAST_VALUE_INTERPOLATION"); }
From source file:de.bsd.hawkularFxReports.Generator.java
public static <T> T mapfromString(String content, TypeReference<T> targetClass) { ObjectMapper mapper = new ObjectMapper(); T ret = null;// w w w. java 2s .co m try { ret = (T) mapper.readValue(content, targetClass); } catch (IOException e) { e.printStackTrace(); // TODO: Customise this generated block } return ret; }
From source file:de.thingweb.typesystem.jsonschema.JsonSchemaType.java
public static JsonType getJsonType(String type) throws JsonSchemaException { JsonType jtype = null;/*from w w w . j a v a 2s. c o m*/ try { // TODO use JSON schema parser if (type != null) { ObjectMapper mapper = new ObjectMapper(); JsonNode jsonSchemaNode = mapper.readValue(new StringReader(type), JsonNode.class); jtype = getJsonType(jsonSchemaNode); } } catch (Exception e) { // failure --> no JSON schema } return jtype; }
From source file:de.thingweb.typesystem.jsonschema.JsonSchemaType.java
private static boolean isOfType(String type, List<String> types) { boolean isOfType = false; try {/*from w w w . jav a 2 s . c o m*/ // TODO use JSON schema parser if (type != null) { ObjectMapper mapper = new ObjectMapper(); JsonNode valueType = mapper.readValue(new StringReader(type), JsonNode.class); if (valueType != null) { JsonNode value = valueType.findValue("type"); if (value != null) { isOfType = types.contains(value.asText()); } } } } catch (Exception e) { // failure --> no JSON schema } return isOfType; }
From source file:edu.usu.sdl.openstorefront.util.ServiceUtil.java
public static String stripeFieldJSON(String json, Set<String> fieldsToKeep) { ObjectMapper mapper = defaultObjectMapper(); try {/*www .ja va 2 s . c o m*/ JsonNode rootNode = mapper.readTree(json); processNode(rootNode, fieldsToKeep); Object jsonString = mapper.readValue(rootNode.toString(), Object.class); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonString); } catch (IOException ex) { throw new OpenStorefrontRuntimeException(ex); } }
From source file:groovyx.net.http.optional.Jackson.java
/** * Used to parse the server response content using the Jackson JSON parser. * * @param config the configuration//from w w w . j av a2 s . c o m * @param fromServer the server content accessor * @return the parsed object */ @SuppressWarnings("WeakerAccess") public static Object parse(final ChainedHttpConfig config, final FromServer fromServer) { try { final ObjectMapper mapper = (ObjectMapper) config.actualContext(fromServer.getContentType(), OBJECT_MAPPER_ID); return mapper.readValue(fromServer.getReader(), config.getChainedResponse().getType()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java
@SuppressWarnings("unchecked") public static List<String> getClasses(JsonNode n, ObjectMapper mapper) throws IOException { List<String> classes = null; if (n.has("types")) classes = mapper.readValue(n.get("types").asText(), List.class); return classes; }
From source file:xyz.monotalk.social.mixcloud.internal.JsonUtils.java
/** * readResultValue/*from w w w . j ava 2s . c o m*/ * * @param <T> * @param json * @param clazz * @return */ public static <T> MixCloudResult<T> readResultValue(String json, Class<T> clazz) { MixCloudResult<T> result = null; ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory().constructParametrizedType(MixCloudResult.class, MixCloudResult.class, clazz); try { result = mapper.readValue(json, type); } catch (IOException ex) { throw new RuntimeException(ex); } return result; }