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.apache.parquet.cli.json.AvroJson.java
public static <T> T parse(String json, Class<T> returnType) { ObjectMapper mapper = new ObjectMapper(); try {/*from ww w . ja va 2 s. c o m*/ return mapper.readValue(json, returnType); } catch (JsonParseException e) { throw new IllegalArgumentException("Invalid JSON", e); } catch (JsonMappingException e) { throw new IllegalArgumentException("Invalid JSON", e); } catch (IOException e) { throw new RuntimeIOException("Cannot initialize JSON parser", e); } }
From source file:org.apache.parquet.cli.json.AvroJson.java
public static <T> T parse(InputStream json, Class<T> returnType) { ObjectMapper mapper = new ObjectMapper(); try {/*from w w w . j av a 2s . c om*/ return mapper.readValue(json, returnType); } catch (JsonParseException e) { throw new IllegalArgumentException("Invalid JSON stream", e); } catch (JsonMappingException e) { throw new IllegalArgumentException("Invalid JSON stream", e); } catch (IOException e) { throw new RuntimeIOException("Cannot initialize JSON parser", e); } }
From source file:com.company.et.service.JsonService.java
public static Professor[] jsonToObjectProfessorArray(String json) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); List<String> json_list = split(json); Professor[] profs = new Professor[json_list.size()]; SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null)) .addDeserializer(Professor.class, new ProfessorDeserializer()); mapper.registerModule(testModule);/*from w w w . j a v a2 s. c o m*/ for (int i = 0; i < json_list.size(); i++) { //System.out.println(json_list.get(i)); profs[i] = mapper.readValue(json_list.get(i), Professor.class); } return profs; }
From source file:facturacion.restClient.EmpresaRest.java
public static Empresa GetEmpresaDetail(String empresa) { try {//from w w w .j a v a 2 s .co m Empresa e = new Empresa(); ObjectMapper mapper = new ObjectMapper(); System.out.println("empresa=" + empresa); WebTarget webTarget = Uri.uriEmpresaDetail(empresa); Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); invocationBuilder.header("some-header", "true"); Response response = invocationBuilder.get(); int in = response.getStatus(); System.out.println("status=" + in); if (in == 200) { String cad = response.readEntity(String.class); e = mapper.readValue(cad, Empresa.class); System.out.println("FULLLLLLLLL"); } else { e = null; System.out.println("EMPTYYYYYYYYy"); } return e; //return (response.getStatus() == 200) ? mapper.readValue(response.readEntity(String.class),Empresa.class) : null; } catch (UnrecognizedPropertyException e) { System.out.println("error en los datooooos de mapeo de la URI"); return null; } catch (ProcessingException e) { System.out.println("Error no se pudo conectar a la URI"); return null; } catch (JsonGenerationException e) { System.out.println("---===> 1"); e.printStackTrace(); return null; } catch (JsonMappingException e) { System.out.println("---===> 2"); e.printStackTrace(); return null; } catch (Exception e) { System.out.println("---===> 3"); e.printStackTrace(); return null; } }
From source file:com.zestedesavoir.zestwriter.utils.Configuration.java
public static String getLastRelease() throws IOException { String projectUrlRelease = "https://api.github.com/repos/firm1/zest-writer/releases/latest"; String json = Request.Get(projectUrlRelease).execute().returnContent().asString(); ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally Map map = mapper.readValue(json, Map.class); if (map.containsKey("tag_name")) { return (String) map.get("tag_name"); }//from ww w . j a v a2 s. c o m return null; }
From source file:com.spotify.heroic.shell.Tasks.java
public static BackendKeyFilter setupKeyFilter(KeyspaceBase params, ObjectMapper mapper) throws Exception { BackendKeyFilter filter = BackendKeyFilter.of(); if (params.start != null) { filter = filter.withStart(//from ww w . j a va2 s . c o m BackendKeyFilter.gte(mapper.readValue(params.start, BackendKeyArgument.class).toBackendKey())); } if (params.startPercentage >= 0) { filter = filter.withStart(BackendKeyFilter.gtePercentage((float) params.startPercentage / 100f)); } if (params.startToken != null) { filter = filter.withStart(BackendKeyFilter.gteToken(params.startToken)); } if (params.end != null) { filter = filter.withEnd( BackendKeyFilter.lt(mapper.readValue(params.end, BackendKeyArgument.class).toBackendKey())); } if (params.endPercentage >= 0) { filter = filter.withEnd(BackendKeyFilter.ltPercentage((float) params.endPercentage / 100f)); } if (params.endToken != null) { filter = filter.withEnd(BackendKeyFilter.ltToken(params.endToken)); } filter = filter.withLimit(params.limit); return filter; }
From source file:de.thingweb.desc.ThingDescriptionParser.java
/** * reshapes the input JSON-LD object using the standard Thing Description * context and having the thing description resource as object root. * //from w w w .jav a 2 s . com * @param data * UTF-8 encoded JSON-LD object * @return the reshaped JSON-LD object * @throws IOException * error */ public static String reshape(byte[] data) throws IOException { ObjectMapper om = new ObjectMapper(); try { Object jsonld = JsonUtils.fromInputStream(new ByteArrayInputStream(data)); // TODO put the frame online instead Object frame = om.readValue("{\"http://www.w3c.org/wot/td#hasMetadata\":{}}", HashMap.class); jsonld = JsonLdProcessor.frame(jsonld, frame, new JsonLdOptions()); return null; // return removeBlankNodes(compactJson(jsonld)).toString(); } catch (JsonLdError e) { throw new IOException("Can't reshape triples", e); } }
From source file:com.amazon.kinesis.streaming.agent.config.Configuration.java
/** * Build a configuration from an input stream containing JSON. * * @param is//from w w w . j a va 2 s. c o m * @return * @throws IOException */ @SuppressWarnings("unchecked") public static Configuration get(InputStream is) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(Feature.ALLOW_COMMENTS, true); return new Configuration( (Map<String, Object>) mapper.readValue(is, new TypeReference<HashMap<String, Object>>() { })); }
From source file:com.ikanow.aleph2.data_model.utils.BeanTemplateUtils.java
/** Creates a property bean from the supplied config object * @param bean_root - the root of the configuration tree that needs to be converted to bean * @param bean_clazz - the class of the properties bean * @return//from w w w. j ava 2 s . c o m * @throws IOException * @throws JsonMappingException * @throws JsonParseException */ static public <T> T from(final Config bean_root, final Class<T> bean_clazz) throws JsonParseException, JsonMappingException, IOException { if (null != bean_root) { ObjectMapper object_mapper = BeanTemplateUtils.configureMapper(Optional.empty()); return object_mapper.readValue(bean_root.root().render(ConfigRenderOptions.concise()), bean_clazz); } else { return BeanTemplateUtils.build(bean_clazz).done().get(); } }
From source file:com.vmware.bdd.cli.commands.CommandsUtils.java
public static <T> T getObjectByJsonString(Class<T> entityType, String jsonString) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = getMapper(); T mappedObject = null;/*w w w. j a v a 2 s .c om*/ mappedObject = mapper.readValue(jsonString, entityType); return mappedObject; }