protected static String toJson(Map<String, ByteIterator> values) throws IOException { ObjectNode node = MAPPER.createObjectNode(); Map<String, String> stringMap = StringByteIterator.getStringMap(values); for (Map.Entry<String, String> pair : stringMap.entrySet()) { node.put(pair.getKey(), pair.getValue()); } JsonFactory jsonFactory = new JsonFactory(); Writer writer = new StringWriter(); JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer); MAPPER.writeTree(jsonGenerator, node); return writer.toString(); } }
/** * Creates a new empty ObjectNode. * * @return a new empty json object. */ public static ObjectNode newObject() { return createObjectMapper().createObjectNode(); }
/** * Creates a new empty ObjectNode. * * @return a new empty json object. */ public static ObjectNode newObject() { return createObjectMapper().createObjectNode(); }
/** * @param keyValues The map to turn into the string. * @return A string of format {"key":"value",...} */ String getMessagesFromMap(final Map<String, String> keyValues) { ObjectNode node = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : keyValues.entrySet()) { node.put(entry.getKey(), entry.getValue()); } return node.size() > 0 ? node.toString() : null; }
/** * Create a Javascript value object with the value being the passed in value. * @param value The {@code String} value to use as the value of the object. * @return A String representation of the Javascript object. */ protected String getValueObject(final String value) { ObjectNode node = mapper.createObjectNode(); node.put("value", value); //$NON-NLS-1$ return node.toString(); }
private JsonNode createValueDatatype(final String datatype, final String value) { final ObjectNode node = mapper.createObjectNode(); node.put(JsonTokenizer.DATATYPE_LABEL, datatype); node.put(JsonTokenizer.DATATYPE_VALUES, value); return node; }
private JsonNode createValueDatatype(final String datatype, final String value) { final ObjectNode node = mapper.createObjectNode(); node.put(ExtendedJsonTokenizer.DATATYPE_LABEL, datatype); node.put(ExtendedJsonTokenizer.DATATYPE_VALUES, value); return node; }
private static String getManagedSchemaEntityVersionSchema(String entityName) { String avroSchemaString = AvroUtils .inputStreamToString(VersionedAvroEntityMapper.class .getResourceAsStream("/ManagedSchemaEntityVersion.avsc")); JsonNode jsonNode = rawSchemaAsJsonNode(avroSchemaString); ObjectMapper mapper = new ObjectMapper(); ObjectNode mappingNode = mapper.createObjectNode(); mappingNode.put("type", "column"); mappingNode.put("value", "_s:sv_" + entityName); ((ObjectNode)jsonNode.get("fields").get(0)).put("mapping", mappingNode); return jsonNode.toString(); }
private ObjectNode buildAvroRecordType(String avroRecordTypeName, final ArrayNode avroFields) throws Xsd2AvroTranslatorException { ObjectNode avroRecord = MAPPER.createObjectNode(); avroRecord.put("type", "record"); avroRecord.put("name", avroRecordTypeName); avroRecord.put("fields", avroFields); return avroRecord; }
public static void configureStudyWithNamespace(StudyImpl study, boolean shouldResolveReferences, String namespace) { study.setSourceId("globi:" + namespace); DatasetImpl originatingDataset = new DatasetImpl(namespace, URI.create(getBaseUrlMaster(namespace))); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, shouldResolveReferences); originatingDataset.setConfig(objectNode); study.setOriginatingDataset(originatingDataset); } }
@Override public ObjectNode toJson(RecordIdPrefixFilter filter, Namespaces namespaces, LRepository repository, RecordFilterJsonConverter<RecordFilter> converter) throws RepositoryException, InterruptedException { ObjectNode node = JsonFormat.OBJECT_MAPPER.createObjectNode(); if (filter.getRecordId() != null) { node.put("recordId", filter.getRecordId().toString()); } return node; }
@BeforeEach public void setUpMockRequest() { ObjectMapper mapper = new ObjectMapper(); ObjectNode mockPluginDef = mapper.createObjectNode(); mockPluginDef.put("foo", "bar"); //$NON-NLS-1$ //$NON-NLS-2$ mockPluginDefinitionsArray = mapper.createArrayNode(); mockPluginDefinitionsArray.add(mockPluginDef); when(mockApplicationModeObject.toString()).thenReturn(APPLICATION_MODE); when(mockRequest.getAttribute(WebAdminHostPageServlet.ATTR_APPLICATION_MODE)).thenReturn(mockApplicationModeObject); when(mockRequest.getAttribute(WebAdminHostPageServlet.ATTR_PLUGIN_DEFS)).thenReturn(mockPluginDefinitionsArray); }
@Override public ObjectNode serialize(ObjectMapper mapper, NerTag nerTag){ ObjectNode jNerTag = mapper.createObjectNode(); jNerTag.put("tag", nerTag.getTag()); if(nerTag.getType() != null){ jNerTag.put("uri", nerTag.getType().getUnicodeString()); } return jNerTag; }
@Override public ObjectNode serialize(ObjectMapper mapper, PhraseTag value) { ObjectNode jTag = mapper.createObjectNode(); jTag.put("tag",value.getTag()); if(value.getCategory() != null){ jTag.put("lc", value.getCategory().ordinal()); } return jTag; }
@Override public ObjectNode serialize(ObjectMapper mapper, NerTag nerTag){ ObjectNode jNerTag = mapper.createObjectNode(); jNerTag.put("tag", nerTag.getTag()); if(nerTag.getType() != null){ jNerTag.put("uri", nerTag.getType().getUnicodeString()); } return jNerTag; }
public static ObjectNode entityListToJson(List<Entity> entityList) throws LeanException { ObjectNode json = getObjectMapper().createObjectNode(); ArrayNode array = getObjectMapper().createArrayNode(); for (Entity entity : entityList) { array.add(entityToJson(entity)); } json.put("result", array); return json; }
@Override public ObjectNode serialize(ObjectMapper mapper, PhraseTag value) { ObjectNode jTag = mapper.createObjectNode(); jTag.put("tag",value.getTag()); if(value.getCategory() != null){ jTag.put("lc", value.getCategory().ordinal()); } return jTag; }
private JsonNode recursiveTreeFromEntity(Entity entity) { ObjectNode aRoot = mapper.createObjectNode(); aRoot.put("name", entity.getDisplayName()); aRoot.put("id", entity.getId()); aRoot.put("type", entity.getEntityType().getName()); if (entity.getChildren().size() != 0) { aRoot.put("children", childEntitiesAsArray(entity)); } return aRoot; } private ArrayNode childEntitiesAsArray(Entity entity) {
@Override ObjectNode toJson() { final ObjectNode obj = mapper.createObjectNode(); final ArrayNode bool = obj.putArray(BooleanPropertyParser.BOOLEAN_PROPERTY); for (final QueryClause clause : clauses) { final ObjectNode e = bool.addObject(); e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString()); e.putAll(clause.getQuery().toJson()); } return obj; }
public static ViewQuery createAndFetchViewQuery() { if (!connector.contains(DESIGN_DOC_ID)) { //The design document doesn't exist in the database so we create it. JsonNode rootNode = mapper.createObjectNode(); ((ObjectNode)rootNode).put("language", "javascript"); ((ObjectNode)rootNode).putObject("views").putObject(TEST_VIEW).put("map", "function(doc) {\n emit(doc._id, doc);\n}"); connector.create(DESIGN_DOC_ID, rootNode); } return new ViewQuery().designDocId(DESIGN_DOC_ID).viewName(TEST_VIEW); }