List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:com.github.fge.jsonschema.process.JsonPatch.java
@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public static Response validate(@FormParam("input") final String patch, @FormParam("input2") final String data) { if (patch == null || data == null) return BAD; try {/* w ww. j a v a 2 s .c o m*/ final JsonNode ret = buildResult(patch, data); return Response.ok().entity(ret.toString()).build(); } catch (IOException e) { log.error("I/O error while validating data", e); return OOPS; } }
From source file:rpc.server.controllers.play.BaseHTTPController.java
public static Result call() { JsonNode json = request().body().asJson(); if (json == null) { return badRequest(); }/*from w w w. ja v a 2 s . c om*/ String body = json.toString(); CallRequest request; try { request = requestSerializer.deserialize(body); } catch (InvalidPayload exception) { return badRequest(exception.toString()); } CallResponse response = GlobalHandler.handle(request); String payload = responseSerializer.serialize(response); response().setContentType("application/json"); if (response.isSuccess()) { return ok(payload); } else { return badRequest(payload); } }
From source file:com.baasbox.service.scripting.js.Api.java
public static String execCommand(String commandStr, JsonCallback callback) { BaasBoxLogger.debug("Command to execute: " + commandStr); try {//from ww w . j a va 2 s . co m JsonNode node = Json.mapper().readTree(commandStr); if (!node.isObject()) { BaasBoxLogger.error("Command is not an object"); throw ECMAErrors.typeError("Invalid command"); } ObjectNode o = (ObjectNode) node; String main = mainModule(); if (main != null) { o.put("main", main); } JsonNode exec = CommandRegistry.execute(node, callback); String res = exec == null ? null : exec.toString(); BaasBoxLogger.debug("Command result: " + res); return res; } catch (IOException e) { BaasBoxLogger.error("IoError " + ExceptionUtils.getMessage(e), e); throw ECMAErrors.typeError(e, "Invalid command definition"); } catch (CommandException e) { BaasBoxLogger.error("CommandError: " + ExceptionUtils.getMessage(e), e); throw new ECMAException(ExceptionUtils.getMessage(e), e); } }
From source file:edu.usu.sdl.openstorefront.util.ServiceUtil.java
public static String stripeFieldJSON(String json, Set<String> fieldsToKeep) { ObjectMapper mapper = defaultObjectMapper(); try {/*from w w w . j a v a2 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:controllers.oer.NtToEs.java
static String jsonLdToRdf(JsonNode data, Lang lang) { StringWriter stringWriter = new StringWriter(); Model model = ModelFactory.createDefaultModel(); for (JsonNode jsonNode : data) { InputStream in = new ByteArrayInputStream(jsonNode.toString().getBytes(Charsets.UTF_8)); RDFDataMgr.read(model, in, Lang.JSONLD); }//ww w.j a v a2 s . co m RDFDataMgr.write(stringWriter, model, lang); return stringWriter.toString(); }
From source file:io.orchestrate.client.AbstractOperation.java
@SuppressWarnings("unchecked") static <T> KvObject<T> jsonToKvObject(final ObjectMapper objectMapper, final JsonNode jsonNode, final Class<T> clazz) throws IOException { // parse the PATH structure (e.g.): // {"collection":"coll","key":"aKey","ref":"someRef"} final JsonNode path = jsonNode.get("path"); final String collection = path.get("collection").asText(); final String key = path.get("key").asText(); final String ref = path.get("ref").asText(); final KvMetadata metadata = new KvMetadata(collection, key, ref); // parse result structure (e.g.): // {"path":{...},"value":{}} final JsonNode valueNode = jsonNode.get("value"); final String rawValue = valueNode.toString(); final T value; if (clazz == String.class) { // don't deserialize JSON data value = (T) rawValue;//from ww w . j av a 2 s . c om } else { value = objectMapper.readValue(rawValue, clazz); } return new KvObject<T>(metadata, value, rawValue); }
From source file:com.geekzone.search.tools.Utils.java
/** * @description Cette fonction permet d'ajouter le champ "hashCode" * au document de l'objet (entit de la BD) avant de l'indexer * @param obj/* w w w . ja v a 2s .c o m*/ * @return * @throws IOException */ public static String addHashCode(Object obj) throws IOException { JsonNode node = mapper.readTree(getDocumentAsString(obj)); ObjectNode on = (ObjectNode) node; on.put("hashCode", getHashCode(obj)); String finalObject = node.toString(); return finalObject; }
From source file:com.meetingninja.csse.database.MeetingDatabaseAdapter.java
public static Meeting parseMeeting(JsonNode node) { logPrint(node.toString()); Meeting m = new Meeting(); // if (m.getID().isEmpty()) // m.setID(node.get(KEY_ID).asText()); m.setTitle(node.get(Keys.Meeting.TITLE).asText()); m.setLocation(node.get(Keys.Meeting.LOCATION).asText()); m.setStartTime(node.get(Keys.Meeting.DATETIME).asText()); m.setEndTime(node.get(Keys.Meeting.OTHEREND).asText()); m.setDescription(node.get(Keys.Meeting.DESC).asText()); JsonNode attendance = node.get(Keys.Meeting.ATTEND); if (attendance != null && attendance.isArray()) { for (final JsonNode attendeeNode : attendance) { String _id = attendeeNode.get("userID").asText(); m.addAttendee(_id);/*w w w . j av a 2 s. c om*/ } } else Log.e(TAG, "Error: Unable to parse meeting attendance"); return m; }
From source file:org.jboss.aerogear.io.netty.handler.codec.sockjs.util.JsonUtil.java
public static String[] decode(final String content) throws IOException { final JsonNode root = MAPPER.readTree(content); if (root.isObject()) { return new String[] { root.toString() }; }/*w ww . j a v a2 s .c o m*/ if (root.isValueNode()) { return new String[] { root.asText() }; } if (!root.isArray()) { throw new JsonMappingException("content must be a JSON Array but was : " + content); } final List<String> messages = new ArrayList<String>(); final Iterator<JsonNode> elements = root.elements(); while (elements.hasNext()) { final JsonNode field = elements.next(); if (field.isValueNode()) { messages.add(field.asText()); } else { messages.add(field.toString()); } } return messages.toArray(new String[messages.size()]); }
From source file:org.trustedanalytics.hadoop.admin.tools.HadoopClientParamsImporter.java
static String returnJSON(Map<String, String> props) { ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.createObjectNode(); props.forEach((k, v) -> ((ObjectNode) rootNode).with(ConfigConstants.HADOOP_CONFIG_KEY_VALUE).put(k, v)); return escapeCharacters(rootNode.toString()); }