Java Code Examples for com.fasterxml.jackson.databind.node.JsonNodeFactory#instance()
The following examples show how to use
com.fasterxml.jackson.databind.node.JsonNodeFactory#instance() .
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: BasicURLNormalizerTest.java From storm-crawler with Apache License 2.0 | 6 votes |
@Test public void testHostIDNtoASCII() throws MalformedURLException { ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put("hostIDNtoASCII", true); URLFilter urlFilter = createFilter(filterParams); URL testSourceUrl = new URL("http://www.example.com/"); String inputURL = "http://señal6.com.ar/"; String expectedURL = "http://xn--seal6-pta.com.ar/"; String normalizedUrl = urlFilter.filter(testSourceUrl, new Metadata(), inputURL); assertEquals("Failed to filter query string", expectedURL, normalizedUrl); inputURL = "http://сфера.укр/"; expectedURL = "http://xn--80aj7acp.xn--j1amh/"; normalizedUrl = urlFilter.filter(testSourceUrl, new Metadata(), inputURL); assertEquals("Failed to filter query string", expectedURL, normalizedUrl); }
Example 2
Source File: BasicURLNormalizerTest.java From storm-crawler with Apache License 2.0 | 6 votes |
@Test public void testHashes() throws MalformedURLException { ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put("removeHashes", true); URLFilter urlFilter = createFilter(filterParams); URL testSourceUrl = new URL("http://florida-chemical.com"); String in = "http://www.florida-chemical.com/Diacetone-Alcohol-DAA-99.html?xid_0b629=12854b827878df26423d933a5baf86d5"; String out = "http://www.florida-chemical.com/Diacetone-Alcohol-DAA-99.html"; String normalizedUrl = urlFilter.filter(testSourceUrl, new Metadata(), in); assertEquals("Failed to filter query string", out, normalizedUrl); in = "http://www.maroongroupllc.com/maroon/login/auth;jsessionid=8DBFC2FEDBD740BBC8B4D1A504A6DE7F"; out = "http://www.maroongroupllc.com/maroon/login/auth"; normalizedUrl = urlFilter.filter(testSourceUrl, new Metadata(), in); assertEquals("Failed to filter query string", out, normalizedUrl); }
Example 3
Source File: DynamoDSETranslatorJSONBlob.java From dynamo-cassandra-proxy with Apache License 2.0 | 6 votes |
private ObjectNode organizeColumns(JsonNode items, AttributeDefinition partitionKey, Optional<AttributeDefinition> clusteringKey) { ObjectNode itemsClone = new ObjectNode(JsonNodeFactory.instance); ObjectNode jsonBlobNode = new ObjectNode(JsonNodeFactory.instance); for (Iterator<Map.Entry<String, JsonNode>> it = items.fields(); it.hasNext(); ) { Map.Entry<String, JsonNode> item = it.next(); String itemKey = item.getKey(); if ( partitionKey.getAttributeName().equals(itemKey) || (clusteringKey.isPresent() && clusteringKey.get().getAttributeName().equals(itemKey))) itemsClone.put("\"" + itemKey + "\"", stripDynamoTypes(item.getValue())); else jsonBlobNode.put(itemKey, item.getValue()); } itemsClone.put("json_blob", items); return itemsClone; }
Example 4
Source File: PluginResultHelper.java From cordova-hot-code-push with MIT License | 6 votes |
private static PluginResult getResult(String action, JsonNode data, JsonNode error) { JsonNodeFactory factory = JsonNodeFactory.instance; ObjectNode resultObject = factory.objectNode(); if (action != null) { resultObject.set(JsParams.General.ACTION, factory.textNode(action)); } if (data != null) { resultObject.set(JsParams.General.DATA, data); } if (error != null) { resultObject.set(JsParams.General.ERROR, error); } return new PluginResult(PluginResult.Status.OK, resultObject.toString()); }
Example 5
Source File: JsonPatchPatchConverter.java From spring-sync with Apache License 2.0 | 6 votes |
/** * Renders a {@link Patch} as a {@link JsonNode}. * @param patch the patch * @return a {@link JsonNode} containing JSON Patch. */ public JsonNode convert(Patch patch) { List<PatchOperation> operations = patch.getOperations(); JsonNodeFactory nodeFactory = JsonNodeFactory.instance; ArrayNode patchNode = nodeFactory.arrayNode(); for (PatchOperation operation : operations) { ObjectNode opNode = nodeFactory.objectNode(); opNode.set("op", nodeFactory.textNode(operation.getOp())); opNode.set("path", nodeFactory.textNode(operation.getPath())); if (operation instanceof FromOperation) { FromOperation fromOp = (FromOperation) operation; opNode.set("from", nodeFactory.textNode(fromOp.getFrom())); } Object value = operation.getValue(); if (value != null) { opNode.set("value", MAPPER.valueToTree(value)); } patchNode.add(opNode); } return patchNode; }
Example 6
Source File: AbstractProducerCustomizer.java From syndesis with Apache License 2.0 | 6 votes |
protected void afterProducer(Exchange exchange) throws IOException { Message in = exchange.getIn(); JsonNodeFactory factory = JsonNodeFactory.instance; ObjectNode statusNode = factory.objectNode(); int response = 400; String info = "No Information"; HttpStatusCode code = in.getBody(HttpStatusCode.class); if (code != null) { response = code.getStatusCode(); info = code.getInfo(); } statusNode.put("Response", response); statusNode.put("Information", info); String json = OBJECT_MAPPER.writeValueAsString(statusNode); in.setBody(json); }
Example 7
Source File: GuardedStringDeserializerTest.java From syncope with Apache License 2.0 | 6 votes |
@Test public void deserialize() throws IOException { Map<String, JsonNode> kids = new HashMap<>(); kids.put(READONLY, node); kids.put(DISPOSED, node); kids.put(ENCRYPTED_BYTES, node); kids.put(BASE64_SHA1_HASH, node); ObjectNode tree = new ObjectNode(JsonNodeFactory.instance, kids); String testString = "randomTestString"; byte[] encryptedBytes = EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(testString.getBytes()); String encryptedString = Base64.getEncoder().encodeToString(encryptedBytes); when(jp.readValueAsTree()).thenReturn(tree); when(node.asText()).thenReturn(encryptedString); assertEquals(Boolean.FALSE, ReflectionTestUtils.getField(deserializer.deserialize(jp, ctx), READONLY)); kids.remove(READONLY); assertEquals(Boolean.FALSE, ReflectionTestUtils.getField(deserializer.deserialize(jp, ctx), DISPOSED)); kids.remove(DISPOSED); assertEquals(encryptedString, ReflectionTestUtils.getField(deserializer.deserialize(jp, ctx), BASE64_SHA1_HASH)); kids.remove(BASE64_SHA1_HASH); GuardedString expected = new GuardedString(new String(testString.getBytes()).toCharArray()); assertTrue(EqualsBuilder.reflectionEquals(ReflectionTestUtils.getField(expected, ENCRYPTED_BYTES), ReflectionTestUtils.getField(deserializer.deserialize(jp, ctx), ENCRYPTED_BYTES))); }
Example 8
Source File: RootJSON.java From lams with GNU General Public License v2.0 | 6 votes |
/** Create JSON objects from the database model */ public RootJSON(NodeModel node, boolean includeCreator) { super(JsonNodeFactory.instance); // create special root level JSON object this.put(IdeaJSON.MAPJS_JSON_ID_KEY, MAPJS_JSON_ROOT_ID_VALUE); this.put("formatVersion", "3"); if (node != null) { this.put(IdeaJSON.MAPJS_JSON_TITLE_KEY, node.getConcept().getText()); } // start the recursion to create the ideas objects ObjectNode ideas = JsonNodeFactory.instance.objectNode(); ideas.set("1", new IdeaJSON(node, 0, includeCreator)); this.set(IdeaJSON.MAPJS_JSON_IDEAS_KEY, ideas); }
Example 9
Source File: JacksonArrayFormatter.java From yosegi with Apache License 2.0 | 5 votes |
@Override public JsonNode writeParser( final IParser parser ) throws IOException { ArrayNode array = new ArrayNode( JsonNodeFactory.instance ); for ( int i = 0 ; i < parser.size() ; i++ ) { IParser childParser = parser.getParser( i ); if ( childParser.isMap() || childParser.isStruct() ) { array.add( JacksonParserToJsonObject.getFromObjectParser( childParser ) ); } else if ( childParser.isArray() ) { array.add( JacksonParserToJsonObject.getFromArrayParser( childParser ) ); } else { array.add( PrimitiveObjectToJsonNode.get( parser.get( i ) ) ); } } return array; }
Example 10
Source File: JsonArraySource.java From yql-plus with Apache License 2.0 | 5 votes |
@Query public JsonResult getJsonArray(int count) { JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance; ArrayNode arrayNode = new ArrayNode(jsonNodeFactory); for (int i = 0; i < count; i++) { arrayNode.add(i); } JsonResult jsonResult = new JsonResult(); jsonResult.jsonNode = arrayNode; return jsonResult; }
Example 11
Source File: BasicURLFilterTest.java From storm-crawler with Apache License 2.0 | 5 votes |
private URLFilter createFilter(int length, int repet) { BasicURLFilter filter = new BasicURLFilter(); ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put("maxPathRepetition", repet); filterParams.put("maxLength", length); Map<String, Object> conf = new HashMap<>(); filter.configure(conf, filterParams); return filter; }
Example 12
Source File: JobRestController.java From genie with Apache License 2.0 | 5 votes |
/** * Get the status of the given job if it exists. * * @param id The id of the job to get status for * @return The status of the job as one of: {@link JobStatus} * @throws NotFoundException When no job with {@literal id} exists */ @GetMapping(value = "/{id}/status", produces = MediaType.APPLICATION_JSON_VALUE) public JsonNode getJobStatus(@PathVariable("id") final String id) throws NotFoundException { log.info("[getJobStatus] Called for job with id: {}", id); final JsonNodeFactory factory = JsonNodeFactory.instance; return factory .objectNode() .set( "status", factory.textNode(DtoConverters.toV3JobStatus(this.persistenceService.getJobStatus(id)).toString()) ); }
Example 13
Source File: ExtractConnectorDescriptorsMojo.java From syndesis with Apache License 2.0 | 5 votes |
private void addComponentMeta(ObjectNode root, ClassLoader classLoader) { // is there any custom Camel components in this library? ObjectNode component = new ObjectNode(JsonNodeFactory.instance); ObjectNode componentMeta = getComponentMeta(classLoader); if (componentMeta != null) { component.set("meta", componentMeta); } addOptionalSchemaAsString(classLoader, component, "schema", "camel-component-schema.json"); if (component.size() > 0) { root.set("component", component); } }
Example 14
Source File: BasicURLNormalizerTest.java From storm-crawler with Apache License 2.0 | 5 votes |
private URLFilter createFilter(boolean removeAnchor, List<String> queryElementsToRemove) { ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.set("queryElementsToRemove", getArrayNode(queryElementsToRemove)); filterParams.put("removeAnchorPart", Boolean.valueOf(removeAnchor)); return createFilter(filterParams); }
Example 15
Source File: JacksonObjectFormatter.java From yosegi with Apache License 2.0 | 5 votes |
@Override public JsonNode writeParser( final IParser parser ) throws IOException { ObjectNode objectNode = new ObjectNode( JsonNodeFactory.instance ); for ( String key : parser.getAllKey() ) { IParser childParser = parser.getParser( key ); if ( childParser.isMap() || childParser.isStruct() ) { objectNode.put( key , JacksonParserToJsonObject.getFromObjectParser( childParser ) ); } else if ( childParser.isArray() ) { objectNode.put( key , JacksonParserToJsonObject.getFromArrayParser( childParser ) ); } else { objectNode.put( key , PrimitiveObjectToJsonNode.get( parser.get( key ) ) ); } } return objectNode; }
Example 16
Source File: PluginResultHelper.java From cordova-hot-code-push with MIT License | 5 votes |
private static JsonNode createErrorNode(int errorCode, String errorDescription) { JsonNodeFactory factory = JsonNodeFactory.instance; ObjectNode errorData = factory.objectNode(); errorData.set(JsParams.Error.CODE, factory.numberNode(errorCode)); errorData.set(JsParams.Error.DESCRIPTION, factory.textNode(errorDescription)); return errorData; }
Example 17
Source File: JsonEventToLogger.java From galeb with Apache License 2.0 | 4 votes |
private JsonEventToLogger(Logger logger) { this(JsonNodeFactory.instance, logger); }
Example 18
Source File: NotifyResponseJSON.java From lams with GNU General Public License v2.0 | 4 votes |
public NotifyResponseJSON(int ok, Long requestId, Long nodeId) { super(JsonNodeFactory.instance); this.put(OK, ok); this.put(REQUEST_ID_KEY, requestId); this.put(NODE_ID_KEY, nodeId); }
Example 19
Source File: Converter.java From incubator-taverna-language with Apache License 2.0 | 4 votes |
public Converter() { jsonNodeFactory = JsonNodeFactory.instance; }
Example 20
Source File: BasicURLNormalizerTest.java From storm-crawler with Apache License 2.0 | 4 votes |
private URLFilter createFilter(boolean removeAnchor, boolean checkValidURI) { ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put("removeAnchorPart", Boolean.valueOf(removeAnchor)); filterParams.put("checkValidURI", Boolean.valueOf(checkValidURI)); return createFilter(filterParams); }