org.codehaus.jackson.map.MappingJsonFactory Java Examples
The following examples show how to use
org.codehaus.jackson.map.MappingJsonFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonUtils.java From binlake with Apache License 2.0 | 6 votes |
public static JsonNode parseJson(String json) throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonFactory f = new MappingJsonFactory(); JsonParser jp = null; JsonNode rootNode = null; try { jp = f.createJsonParser(json); rootNode = mapper.readTree(jp); } catch (Exception e) { throw e; } finally { if (jp != null) jp.close(); } return rootNode; }
Example #2
Source File: HelloWorldIT.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testJsonRoundtrip() throws Exception { List<Object> providers = new ArrayList<>(); providers.add(new org.codehaus.jackson.jaxrs.JacksonJsonProvider()); JsonBean inputBean = new JsonBean(); inputBean.setVal1("Maple"); WebClient client = WebClient.create(endpointUrl + "/hello/jsonBean", providers); Response r = client.accept("application/json") .type("application/json") .post(inputBean); assertEquals(Response.Status.OK.getStatusCode(), r.getStatus()); MappingJsonFactory factory = new MappingJsonFactory(); JsonParser parser = factory.createJsonParser((InputStream)r.getEntity()); JsonBean output = parser.readValueAs(JsonBean.class); assertEquals("Maple", output.getVal2()); }
Example #3
Source File: PNetGenerationCommand.java From workcraft with MIT License | 4 votes |
public static void initParse(String args) throws IOException { JsonFactory f = new MappingJsonFactory(); JsonParser jp = f.createJsonParser(new File(args)); JsonToken current; current = jp.nextToken(); if (current != JsonToken.START_OBJECT) { LogUtils.logError("Root should be object: quiting."); return; } while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldName = jp.getCurrentName(); // move from field name to field value current = jp.nextToken(); if ("NETWORK".equals(fieldName)) { if (current == JsonToken.START_ARRAY) { // For each of the records in the array System.out.println("Generate CPNs"); while (jp.nextToken() != JsonToken.END_ARRAY) { JsonNode node = jp.readValueAsTree(); String idName = node.get("id").toString(); String idName1 = ""; String idName2 = ""; String idNamep = ""; String idNamep1 = ""; String idNamep2 = ""; String typeName = node.get("type").toString(); //System.out.println("id: " + idName + "type: " + typeName); lst2.add(new Ids(idName, typeName)); JsonNode y = node.get("outs"); if (y != null) { for (int i = 0; y.has(i); i++) { if (y.get(i).has("id")) { if (i == 0) { idName1 = y.get(i).get("id").toString(); idNamep1 = y.get(i).get("in_port").toString(); if ("xfork".equals(typeName)) { lst.add(new Info(idName1, idName, "b", idNamep1)); } else if ("xswitch".equals(typeName)) { lst.add(new Info(idName1, idName, "a", idNamep1)); } else { lst.add(new Info(idName1, idName, "", idNamep1)); } if (idName1.contains("Sync")) { //System.out.println("id: " + idName + "sync: " + idName1); slsti.add(new Info(idName, idName1, "", idNamep1)); //swapped order slsti slsto } //add o based on order of i or reverse? if (idName.contains("Sync")) { slsto2.add(new Info(idName1, idName, "", idNamep1)); } } else if (i == 1) { idName2 = y.get(i).get("id").toString(); idNamep2 = y.get(i).get("in_port").toString(); if ("xfork".equals(typeName)) { lst.add(new Info(idName2, idName, "a", idNamep2)); } else if ("xswitch".equals(typeName)) { lst.add(new Info(idName2, idName, "b", idNamep2)); } else { lst.add(new Info(idName2, idName, "", idNamep2)); } if (idName2.contains("Sync")) slsti.add(new Info(idName, idName2, "", idNamep2)); if (idName.contains("Sync")) { slsto2.add(new Info(idName2, idName, "", idNamep2)); } } else { idName1 = y.get(i).get("id").toString(); idNamep = y.get(i).get("in_port").toString(); if (idName.contains("Sync")) { slsto2.add(new Info(idName, idName1, "", idNamep)); } } } } } } } else { LogUtils.logError("Records should be an array: skipping."); jp.skipChildren(); } } else { //System.out.println("Unprocessed property: " + fieldName); jp.skipChildren(); } } }