List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:me.tfeng.play.avro.AvroHelper.java
public static String convertFromSimpleRecord(Schema schema, String json) throws IOException { if (json.isEmpty()) { return json; }/*from ww w. j ava 2 s. co m*/ JsonNode node = Json.parse(json); node = convertFromSimpleRecord(schema, node); return node.toString(); }
From source file:me.tfeng.toolbox.avro.AvroHelper.java
public static String convertToSimpleRecord(Schema schema, String json) throws IOException { if (json.isEmpty()) { return json; }/* www .j a va2s . c o m*/ JsonNode node = MAPPER.readTree(json); node = convertToSimpleRecord(schema, node); return node.toString(); }
From source file:me.tfeng.toolbox.avro.AvroHelper.java
public static String convertFromSimpleRecord(Schema schema, String json) throws IOException { if (json.isEmpty()) { return json; }/*from www . j a v a2s.co m*/ JsonNode node = MAPPER.readTree(json); node = convertFromSimpleRecord(schema, node); return node.toString(); }
From source file:me.tfeng.toolbox.avro.AvroHelper.java
public static Object createGenericRequestFromRecord(Schema requestSchema, JsonNode record) throws IOException { JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(requestSchema, record.toString()); return new GenericDatumReader<>(requestSchema, requestSchema).read(null, jsonDecoder); }
From source file:com.pros.jsontransform.sort.ArraySortAscending.java
public static void sort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) throws ObjectTransformerException { // check $ascending arguments if (sortNode.get(ArraySort.$ASCENDING.name().toLowerCase()).get(ArraySort.ARGUMENT_BY) == null) { throw new ObjectTransformerException( "Missing argument " + ArraySort.ARGUMENT_BY + " in sort directive " + sortNode.toString()); }/* ww w . j a v a 2s . c o m*/ doSort(arrayNode, sortNode, transformer); }
From source file:com.pros.jsontransform.sort.ArraySortDescending.java
public static void sort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) throws ObjectTransformerException { // check $ascending arguments if (sortNode.get(ArraySort.$DESCENDING.name().toLowerCase()).get(ArraySort.ARGUMENT_BY) == null) { throw new ObjectTransformerException( "Missing argument " + ArraySort.ARGUMENT_BY + " in sort directive " + sortNode.toString()); }/* ww w. j av a 2 s. c o m*/ doSort(arrayNode, sortNode, transformer); }
From source file:me.tfeng.toolbox.avro.AvroHelper.java
public static <T> T createSpecificRequestFromRecord(Class<T> requestClass, JsonNode record) throws IOException { JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(getSchema(requestClass), record.toString()); return new SpecificDatumReader<>(requestClass).read(null, jsonDecoder); }
From source file:com.baasbox.configuration.PropertiesConfigurationHelper.java
public static String dumpConfigurationAsJson() { ImmutableCollection<String> keys = CONFIGURATION_SECTIONS.keySet(); ObjectMapper mapper = new ObjectMapper(); JsonFactory jfactory = mapper.getJsonFactory(); StringWriter sw = new StringWriter(); try {/*from w w w . j a v a 2s.c om*/ JsonGenerator gen = jfactory.createJsonGenerator(sw); gen.writeStartArray(); for (String v : keys) { String st = dumpConfigurationAsJson(v); ObjectMapper op = new ObjectMapper(); JsonNode p = op.readTree(st); BaasBoxLogger.debug("OBJECT:" + p.toString()); BaasBoxLogger.debug("STRING:" + st); //JsonParser jp = jfactory.createJsonParser(st); gen.writeTree(p); } gen.writeEndArray(); gen.close(); return sw.toString(); } catch (Exception e) { BaasBoxLogger.error("Cannot generate a json for the configuration", e); } return "[]"; }
From source file:com.msopentech.odatajclient.testservice.utils.Commons.java
public static InputStream changeFormat(final InputStream is, final Accept target) { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {//from w ww. j a va 2s .c o m IOUtils.copy(is, bos); IOUtils.closeQuietly(is); final ObjectMapper mapper = new ObjectMapper(); final JsonNode node = changeFormat( (ObjectNode) mapper.readTree(new ByteArrayInputStream(bos.toByteArray())), target); return IOUtils.toInputStream(node.toString()); } catch (Exception e) { LOG.error("Error changing format", e); return new ByteArrayInputStream(bos.toByteArray()); } finally { IOUtils.closeQuietly(is); } }
From source file:models.metadata.UserGroup.java
public static UserGroup one(long id) { JsonNode jsonNode = APICall.callAPI(GET_ONE_GROUP + id); UserGroup newGroup = new UserGroup(); if (jsonNode == null || jsonNode.has("error") || jsonNode.isArray()) { return newGroup; }/*from w w w . j a v a 2 s . c om*/ Gson gson = new Gson(); newGroup = gson.fromJson(jsonNode.toString(), UserGroup.class); return newGroup; }