Java Code Examples for com.fasterxml.jackson.databind.ObjectMapper#getFactory()
The following examples show how to use
com.fasterxml.jackson.databind.ObjectMapper#getFactory() .
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: SnowflakeGCSClient.java From snowflake-jdbc with Apache License 2.0 | 6 votes |
private AbstractMap.SimpleEntry<String, String> parseEncryptionData(String jsonEncryptionData) throws SnowflakeSQLException { ObjectMapper mapper = ObjectMapperFactory.getObjectMapper(); JsonFactory factory = mapper.getFactory(); try { JsonParser parser = factory.createParser(jsonEncryptionData); JsonNode encryptionDataNode = mapper.readTree(parser); String iv = encryptionDataNode.get("ContentEncryptionIV").asText(); String key = encryptionDataNode.get("WrappedContentKey").get("EncryptedKey").asText(); return new AbstractMap.SimpleEntry<>(key, iv); } catch (Exception ex) { throw new SnowflakeSQLException(ex, SqlState.SYSTEM_ERROR, ErrorCode.IO_ERROR.getMessageCode(), "Error parsing encryption data as json" + ": " + ex.getMessage()); } }
Example 2
Source File: ClientRPCStoreTest.java From seldon-server with Apache License 2.0 | 6 votes |
@Test public void testGetPredictRequestFromJson() throws JsonParseException, IOException, NoSuchMethodException, SecurityException { mockClientConfigHandler.addListener((ClientConfigUpdateListener) EasyMock.anyObject()); EasyMock.expectLastCall().once(); replay(mockClientConfigHandler); final String client = "test"; ClientRpcStore store = new ClientRpcStore(mockClientConfigHandler); final String json = "{\"meta\":{\"puid\":1234},\"data\":{\"@type\":\"type.googleapis.com/io.seldon.api.rpc.example.CustomPredictRequest\",\"data\":[1.2]}}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode actualObj = mapper.readTree(parser); store.add(client, CustomPredictRequest.class,null,CustomPredictRequest.class.getMethod("newBuilder"),null); ClassificationRequest request = store.getPredictRequestFromJson(client, actualObj); Assert.assertNotNull(request); System.out.println(request); }
Example 3
Source File: ClientRPCStoreTest.java From seldon-server with Apache License 2.0 | 6 votes |
@Test public void testGetPredictReplyFromJsonWithNoType() throws JsonParseException, IOException, NoSuchMethodException, SecurityException { mockClientConfigHandler.addListener((ClientConfigUpdateListener) EasyMock.anyObject()); EasyMock.expectLastCall().once(); replay(mockClientConfigHandler); final String client = "test"; ClientRpcStore store = new ClientRpcStore(mockClientConfigHandler); final String json = "{\"meta\":{\"modelName\":\"some-name\"},\"custom\":{\"data\":\"some custom data\"}}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode actualObj = mapper.readTree(parser); store.add(client, null, CustomPredictReply.class,null,CustomPredictReply.class.getMethod("newBuilder")); ClassificationReply reply = store.getPredictReplyFromJson(client, actualObj); Assert.assertNotNull(reply); System.out.println(reply); }
Example 4
Source File: ClientRPCStoreTest.java From seldon-server with Apache License 2.0 | 6 votes |
@Test public void testGetPredictReplyFromJson() throws JsonParseException, IOException, NoSuchMethodException, SecurityException { mockClientConfigHandler.addListener((ClientConfigUpdateListener) EasyMock.anyObject()); EasyMock.expectLastCall().once(); replay(mockClientConfigHandler); final String client = "test"; ClientRpcStore store = new ClientRpcStore(mockClientConfigHandler); final String json = "{\"meta\":{\"modelName\":\"some-name\"},\"custom\":{\"@type\":\"type.googleapis.com/io.seldon.api.rpc.example.CustomPredictReply\",\"data\":\"some custom data\"}}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode actualObj = mapper.readTree(parser); store.add(client, null, CustomPredictReply.class,null,CustomPredictReply.class.getMethod("newBuilder")); ClassificationReply reply = store.getPredictReplyFromJson(client, actualObj); Assert.assertNotNull(reply); System.out.println(reply); }
Example 5
Source File: PredictionBusinessServiceImpl.java From seldon-server with Apache License 2.0 | 6 votes |
private JsonNode getValidatedJson(ConsumerBean consumer,String jsonRaw,boolean addExtraFeatures) throws JsonParseException, IOException { ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(jsonRaw); JsonNode actualObj = mapper.readTree(parser); if (addExtraFeatures) // only for events not at predict time { ((ObjectNode) actualObj).put(CLIENT_KEY,consumer.getShort_name()); if (actualObj.get(TIMESTAMP_KEY) == null) { ((ObjectNode) actualObj).put(TIMESTAMP_KEY,getTimeStamp()); } else { JsonNode timeNode = actualObj.get(TIMESTAMP_KEY); if (!(timeNode.isInt() || timeNode.isLong())) { throw new APIException(APIException.INVALID_JSON); } } } return actualObj; }
Example 6
Source File: ClientRpcStore.java From seldon-server with Apache License 2.0 | 6 votes |
private JsonNode getDefaultRequestJSON(Message msg) throws JsonParseException, IOException { Message.Builder o2 = DefaultCustomPredictRequest.newBuilder(); TypeRegistry registry = TypeRegistry.newBuilder().add(o2.getDescriptorForType()).build(); JsonFormat.Printer jPrinter = JsonFormat.printer(); String result = jPrinter.usingTypeRegistry(registry).print(msg); ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(result); JsonNode jNode = mapper.readTree(parser); if (jNode.has(PredictionBusinessServiceImpl.REQUEST_CUSTOM_DATA_FIELD)) { JsonNode values = jNode.get(PredictionBusinessServiceImpl.REQUEST_CUSTOM_DATA_FIELD).get("values"); ((ObjectNode) jNode).set(PredictionBusinessServiceImpl.REQUEST_CUSTOM_DATA_FIELD, values); } return jNode; }
Example 7
Source File: ExportUtils.java From keycloak with Apache License 2.0 | 6 votes |
public static void exportFederatedUsersToStream(KeycloakSession session, RealmModel realm, List<String> usersToExport, ObjectMapper mapper, OutputStream os, ExportOptions options) throws IOException { JsonFactory factory = mapper.getFactory(); JsonGenerator generator = factory.createGenerator(os, JsonEncoding.UTF8); try { if (mapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) { generator.useDefaultPrettyPrinter(); } generator.writeStartObject(); generator.writeStringField("realm", realm.getName()); // generator.writeStringField("strategy", strategy.toString()); generator.writeFieldName("federatedUsers"); generator.writeStartArray(); for (String userId : usersToExport) { UserRepresentation userRep = ExportUtils.exportFederatedUser(session, realm, userId, options); generator.writeObject(userRep); } generator.writeEndArray(); generator.writeEndObject(); } finally { generator.close(); } }
Example 8
Source File: ClientRPCStoreTest.java From seldon-server with Apache License 2.0 | 6 votes |
@Test public void testDefaultRequestToJSON() throws JsonParseException, IOException, NoSuchMethodException, SecurityException { mockClientConfigHandler.addListener((ClientConfigUpdateListener) EasyMock.anyObject()); EasyMock.expectLastCall().once(); replay(mockClientConfigHandler); final String client = "test"; ClientRpcStore store = new ClientRpcStore(mockClientConfigHandler); DefaultCustomPredictRequest customRequest = DefaultCustomPredictRequest.newBuilder().addValues(1.0f).build(); Any anyMsg = Any.pack(customRequest); ClassificationRequestMeta meta = ClassificationRequestMeta.newBuilder().setPuid("1234").build(); ClassificationRequest request = ClassificationRequest.newBuilder().setMeta(meta).setData(anyMsg).build(); System.out.println(request); JsonNode json = store.getJSONForRequest(client, request); Assert.assertNotNull(json); System.out.println(json); ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json.toString()); JsonNode actualObj = mapper.readTree(parser); ClassificationRequest req = store.getPredictRequestFromJson(client, actualObj); Assert.assertNotNull(req); System.out.println(req); }
Example 9
Source File: ClientRPCStoreTest.java From seldon-server with Apache License 2.0 | 6 votes |
@Test public void testGetPredictRequestFromJsonWithNoType() throws JsonParseException, IOException, NoSuchMethodException, SecurityException { mockClientConfigHandler.addListener((ClientConfigUpdateListener) EasyMock.anyObject()); EasyMock.expectLastCall().once(); replay(mockClientConfigHandler); final String client = "test"; ClientRpcStore store = new ClientRpcStore(mockClientConfigHandler); final String json = "{\"meta\":{\"puid\":1234},\"data\":{\"data\":[1.2]}}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode actualObj = mapper.readTree(parser); store.add(client, CustomPredictRequest.class,null,CustomPredictRequest.class.getMethod("newBuilder"),null); ClassificationRequest request = store.getPredictRequestFromJson(client, actualObj); Assert.assertNotNull(request); System.out.println(request); }
Example 10
Source File: RequestTest.java From seldon-server with Apache License 2.0 | 5 votes |
@Test public void testActionPatterns2() throws JsonParseException, IOException { String json = "{\"consumer\":\"dailyrecord\",\"httpmethod\":\"GET\",\"path\":\"/items/22/actions\",\"exectime\":\"34\",\"time\":123456789}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode jNode = mapper.readTree(parser); Request r = new Request(jNode); Assert.assertNotNull(r); Assert.assertEquals("/items/{itemid}/actions", r.path); }
Example 11
Source File: RequestTest.java From seldon-server with Apache License 2.0 | 5 votes |
@Test public void testActionPatterns() throws JsonParseException, IOException { String json = "{\"consumer\":\"dailyrecord\",\"httpmethod\":\"GET\",\"path\":\"/users/22/actions\",\"exectime\":\"34\",\"time\":123456789}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode jNode = mapper.readTree(parser); Request r = new Request(jNode); Assert.assertNotNull(r); Assert.assertEquals("/users/{userid}/actions", r.path); }
Example 12
Source File: RequestTest.java From seldon-server with Apache License 2.0 | 5 votes |
@Test public void testActionPatterns4() throws JsonParseException, IOException { String json = "{\"consumer\":\"dailyrecord\",\"httpmethod\":\"GET\",\"path\":\"/items/22/actions/33\",\"exectime\":\"34\",\"time\":123456789}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode jNode = mapper.readTree(parser); Request r = new Request(jNode); Assert.assertNotNull(r); Assert.assertEquals("/items/{itemid}/actions/{userid}", r.path); }
Example 13
Source File: RequestTest.java From seldon-server with Apache License 2.0 | 5 votes |
@Test public void testActionPatterns5() throws JsonParseException, IOException { String json = "{\"consumer\":\"dailyrecord\",\"httpmethod\":\"GET\",\"path\":\"/actions/22\",\"exectime\":\"34\",\"time\":123456789}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode jNode = mapper.readTree(parser); Request r = new Request(jNode); Assert.assertNotNull(r); Assert.assertEquals("/actions/{actionid}", r.path); }
Example 14
Source File: RequestTest.java From seldon-server with Apache License 2.0 | 5 votes |
@Test public void testItemPatterns() throws JsonParseException, IOException { String json = "{\"consumer\":\"dailyrecord\",\"httpmethod\":\"GET\",\"path\":\"/items/22\",\"exectime\":\"34\",\"time\":123456789}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode jNode = mapper.readTree(parser); Request r = new Request(jNode); Assert.assertNotNull(r); Assert.assertEquals("/items/{itemid}", r.path); }
Example 15
Source File: RequestTest.java From seldon-server with Apache License 2.0 | 5 votes |
@Test public void testRecommendationPattern() throws JsonParseException, IOException { String json = "{\"consumer\":\"dailyrecord\",\"httpmethod\":\"GET\",\"path\":\"/users/22/recommendations\",\"exectime\":\"34\",\"time\":123456789}"; ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(json); JsonNode jNode = mapper.readTree(parser); Request r = new Request(jNode); Assert.assertNotNull(r); Assert.assertEquals("/users/{userid}/recommendations", r.path); }
Example 16
Source File: ClientRpcStore.java From seldon-server with Apache License 2.0 | 5 votes |
private JsonNode getJSON(Message msg,String fieldname) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonParseException, IOException { JsonFormat.Printer jPrinter = JsonFormat.printer(); String result = jPrinter.print(msg); ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); JsonParser parser = factory.createParser(result); JsonNode jNode = mapper.readTree(parser); return jNode; }
Example 17
Source File: JacksonJsonDataFormatWriter.java From camunda-spin with Apache License 2.0 | 5 votes |
public void writeToWriter(Writer writer, Object input) { final ObjectMapper objectMapper = dataFormat.getObjectMapper(); final JsonFactory factory = objectMapper.getFactory(); try { JsonGenerator generator = factory.createGenerator(writer); objectMapper.writeTree(generator, (JsonNode) input); } catch (IOException e) { throw LOG.unableToWriteJsonNode(e); } }
Example 18
Source File: PrettyPrintingJsonBodyFilter.java From logbook with MIT License | 4 votes |
public PrettyPrintingJsonBodyFilter(final ObjectMapper mapper) { this(mapper.getFactory()); }
Example 19
Source File: FastJsonHttpLogFormatter.java From logbook with MIT License | 4 votes |
public FastJsonHttpLogFormatter(final ObjectMapper mapper) { this(mapper.getFactory()); }
Example 20
Source File: JsonSchemaAssertions.java From Bastion with GNU General Public License v3.0 | 4 votes |
private JsonNode convertResponseToJsonNode(ModelResponse<?> response) throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonFactory factory = mapper.getFactory(); return factory.createParser(response.getBody()).readValueAsTree(); }