private static JsonProvider getProvider() { Thread thread = Thread.currentThread(); ClassLoader loader = thread.getContextClassLoader(); synchronized (_providerMap) { SoftReference<JsonProvider> providerRef = _providerMap.get(loader); JsonProvider provider = null; if (providerRef != null) { provider = providerRef.get(); } if (provider == null) { provider = createProvider(); _providerMap.put(loader, new SoftReference<>(provider)); } return provider; } }
@Override public JsonObject convert(MarkerPost value) { final JsonObjectBuilder builder = JsonProvider.provider() .createObjectBuilder(); builder.add("type", "Feature"); builder.add("geometry", DoublesToPointGeometryJsonObjectConverter.INSTANCE .convert(value.getCoordinates())); final JsonObjectBuilder properties = JsonProvider.provider() .createObjectBuilder(); properties.add("id", value.getId()); properties.add("lineId", value.getRailwayLineId()); properties.add("lineCode", value.getRailwayLineCode()); properties.add("lineName", value.getRailwayLineGeographicalName()); properties.add("location", value.getLocation()); builder.add("properties", properties); return builder.build(); }
@Override public void start() throws IOException { if (generator != null) { throw new IllegalStateException( "Invalid state, serializer was already started."); } else { os = new FileOutputStream(ouputFile); generator = JsonProvider .provider() .createGeneratorFactory( Collections.singletonMap( JsonGenerator.PRETTY_PRINTING, true)) .createGenerator(os); generator.writeStartObject().write("type", "FeatureCollection") .writeStartArray("features"); } }
@Test public void testJsonObject() { final JsonObjectBuilder objBuilder = JsonProvider.provider().createObjectBuilder(); objBuilder.add("boolTrue", Boolean.TRUE).add("boolFalse", Boolean.FALSE) .addNull("null").add("str", "String"); JsonArrayBuilder arrBuilder = JsonProvider.provider().createArrayBuilder(); arrBuilder.add(11L).add(Boolean.FALSE).add(BigDecimal.TEN); objBuilder.add("array", arrBuilder); JsonObject object = objBuilder.build(); String expected = "{\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"str\":\"String\",\"array\":[11,false,10]}"; assertEquals(expected, jsonb.toJson(object)); JsonObject result = jsonb.fromJson(expected, JsonObject.class); assertEquals(object, result); }
@Test public void testBson () throws IOException { BasicConfigurator.configure (); String f = "../tests/data/data1.bson"; File file = new File (f.replace ('/', File.separatorChar)); JsonPathProvider provider = new JsonPathProvider (); Configuration pathConfig = Configuration.defaultConfiguration ().jsonProvider (provider); JsonPath path = JsonPath.compile ("$..A"); JsonProvider p = new CookJsonProvider (); HashMap<String, Object> readConfig = new HashMap<String, Object> (); readConfig.put (CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_BSON); readConfig.put (CookJsonProvider.ROOT_AS_ARRAY, Boolean.TRUE); JsonReaderFactory rf = p.createReaderFactory (readConfig); JsonReader reader = rf.createReader (new FileInputStream (file)); JsonStructure obj = reader.read (); reader.close (); JsonValue value = path.read (obj, pathConfig); Assert.assertEquals ("[1,3,5,7]", provider.toJson (value)); }
@Test public void readerWriterTest () throws IOException { File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar)); JsonProvider provider = new CookJsonProvider (); // create reader HashMap<String, Object> readConfig = new HashMap<String, Object> (); JsonReaderFactory rf = provider.createReaderFactory (readConfig); JsonReader reader = rf.createReader (new InputStreamReader (new FileInputStream (file), BOM.utf8)); JsonStructure obj = reader.read (); reader.close (); // write it out File dstFile = testFolder.newFile (); HashMap<String, Object> writeConfig = new HashMap<String, Object> (); JsonWriterFactory wf = provider.createWriterFactory (writeConfig); JsonWriter writer = wf.createWriter (new OutputStreamWriter (new FileOutputStream (dstFile), BOM.utf8)); writer.write (obj); writer.close (); Assert.assertEquals (file.length (), dstFile.length ()); }
@Test public void charsetTest () throws IOException { File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar)); JsonProvider provider = new CookJsonProvider (); // create reader HashMap<String, Object> readConfig = new HashMap<String, Object> (); JsonReaderFactory rf = provider.createReaderFactory (readConfig); JsonReader reader = rf.createReader (new FileInputStream (file), BOM.utf8); JsonStructure obj = reader.read (); reader.close (); // write it out File dstFile = testFolder.newFile (); HashMap<String, Object> writeConfig = new HashMap<String, Object> (); JsonWriterFactory wf = provider.createWriterFactory (writeConfig); JsonWriter writer = wf.createWriter (new FileOutputStream (dstFile), BOM.utf8); writer.write (obj); writer.close (); Assert.assertEquals (file.length (), dstFile.length ()); }
@Test public void streamTest () throws IOException { File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar)); JsonProvider provider = new CookJsonProvider (); // create reader HashMap<String, Object> readConfig = new HashMap<String, Object> (); JsonReaderFactory rf = provider.createReaderFactory (readConfig); JsonReader reader = rf.createReader (new FileInputStream (file)); JsonStructure obj = reader.read (); reader.close (); // write it out File dstFile = testFolder.newFile (); HashMap<String, Object> writeConfig = new HashMap<String, Object> (); JsonWriterFactory wf = provider.createWriterFactory (writeConfig); JsonWriter writer = wf.createWriter (new FileOutputStream (dstFile)); writer.write (obj); writer.close (); Assert.assertEquals (file.length (), dstFile.length ()); }
void testFile (String f1, String f2, boolean smallBuf) throws IOException { File file1 = new File (f1.replace ('/', File.separatorChar)); File file2 = new File (f2.replace ('/', File.separatorChar)); StringWriter out1 = new StringWriter (); JsonParser p1 = getJsonParser (file1, smallBuf); JsonGenerator g1 = new TextJsonGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); StringWriter out2 = new StringWriter (); JsonProvider provider = new org.glassfish.json.JsonProviderImpl (); JsonParser p2 = provider.createParser (new FileInputStream (file2)); JsonGenerator g2 = new TextJsonGenerator (out2); Utils.convert (p2, g2); p2.close (); g2.close (); Assert.assertEquals (out1.toString (), out2.toString ()); }
void testFile (String f) throws IOException { File file = new File (f.replace ('/', File.separatorChar)); JsonProvider provider = new org.glassfish.json.JsonProviderImpl (); StringWriter out1 = new StringWriter (); JsonParser p1 = provider.createParser (new FileInputStream (file)); HashMap<String, Object> config = new HashMap<String, Object> (); config.put (JsonGenerator.PRETTY_PRINTING, Boolean.TRUE); JsonGenerator g1 = new CookJsonProvider ().createGeneratorFactory (config).createGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); String original = Utils.getString (file); Assert.assertEquals (out1.toString (), original); }
private void eventCount (String f, int expect) throws IOException { File file = new File (f.replace ('/', File.separatorChar)); JsonValue value; TextJsonParser p = getJsonParser (file); p.next (); value = p.getValue (); p.close (); JsonProvider provider = new CookJsonProvider (); JsonParser p2 = createParser (provider, value); int count; for (count = 0; p2.hasNext (); ++count) p2.next (); p2.close (); Assert.assertEquals (expect, count);; }
@Test public void testDefault () { JsonProvider provider = new CookJsonProvider (); JsonObjectBuilder builder = provider.createObjectBuilder (); JsonObject obj = builder .add ("string", "test") .add ("int", 1234) .add ("true", true) .add ("false", false) .addNull ("null") .build (); Assert.assertEquals ("test", obj.getString ("string", "asdf")); Assert.assertEquals (1234, obj.getInt ("int", 890)); Assert.assertEquals (true, obj.getBoolean ("true", false)); Assert.assertEquals (false, obj.getBoolean ("false", true)); Assert.assertEquals ("test", obj.getString ("no", "test")); Assert.assertEquals (1234, obj.getInt ("no", 1234)); Assert.assertEquals (true, obj.getBoolean ("no", true)); Assert.assertEquals (false, obj.getBoolean ("no", false)); }
@Test public void testGet () { JsonProvider provider = new CookJsonProvider (); JsonObjectBuilder builder = provider.createObjectBuilder (); JsonObject obj = builder .add ("string", "test") .add ("int", 1234) .add ("true", true) .add ("false", false) .addNull ("null") .build (); Assert.assertEquals ("test", obj.getString ("string")); Assert.assertEquals (1234, obj.getInt ("int")); Assert.assertEquals (true, obj.getBoolean ("true")); Assert.assertEquals (false, obj.getBoolean ("false")); Assert.assertEquals (true, obj.isNull ("null")); }
@Test public void testDefault () { JsonProvider provider = new CookJsonProvider (); JsonArrayBuilder builder = provider.createArrayBuilder (); JsonArray array = builder .add ("test") .add (1234) .add (true) .add (false) .addNull () .build (); Assert.assertEquals ("test", array.getString (0, "asdf")); Assert.assertEquals (1234, array.getInt (1, 890)); Assert.assertEquals (true, array.getBoolean (2, false)); Assert.assertEquals (false, array.getBoolean (3, true)); Assert.assertEquals ("test", array.getString (11, "test")); Assert.assertEquals (1234, array.getInt (11, 1234)); Assert.assertEquals (true, array.getBoolean (11, true)); Assert.assertEquals (false, array.getBoolean (11, false)); }
@Test public void testGet () { JsonProvider provider = new CookJsonProvider (); JsonArrayBuilder builder = provider.createArrayBuilder (); JsonArray array = builder .add ("test") .add (1234) .add (true) .add (false) .addNull () .build (); Assert.assertEquals ("test", array.getString (0)); Assert.assertEquals (1234, array.getInt (1)); Assert.assertEquals (true, array.getBoolean (2)); Assert.assertEquals (false, array.getBoolean (3)); Assert.assertEquals (true, array.isNull (4)); }
void testFile (String f) throws IOException { File file = new File (f.replace ('/', File.separatorChar)); JsonProvider provider = new org.glassfish.json.JsonProviderImpl (); StringWriter out1 = new StringWriter (); JsonParser p1 = provider.createParser (new FileInputStream (file)); TextJsonGenerator g1 = new TextJsonGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); StringWriter out2 = new StringWriter (); JsonParser p2 = provider.createParser (new FileInputStream (file)); JsonGenerator g2 = provider.createGenerator (out2); Utils.convert (p2, g2); p2.close (); g2.close (); Assert.assertEquals (out1.toString (), out2.toString ()); }
void testFile (String f, int buffType) throws IOException { File file = new File (f.replace ('/', File.separatorChar)); StringWriter out1 = new StringWriter (); UTF8TextJsonParser p1 = getJsonParser (file, buffType); TextJsonGenerator g1 = new TextJsonGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); StringWriter out2 = new StringWriter (); JsonProvider provider = new org.glassfish.json.JsonProviderImpl (); JsonParser p2 = provider.createParser (new FileInputStream (file)); JsonGenerator g2 = new TextJsonGenerator (out2); Utils.convert (p2, g2); p2.close (); g2.close (); Assert.assertEquals (out2.toString (), out1.toString ()); }
void testFile (String f, int buffType) throws IOException { File file = new File (f.replace ('/', File.separatorChar)); StringWriter out1 = new StringWriter (); TextJsonParser p1 = getJsonParser (file, buffType); TextJsonGenerator g1 = new TextJsonGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); StringWriter out2 = new StringWriter (); JsonProvider provider = new org.glassfish.json.JsonProviderImpl (); JsonParser p2 = provider.createParser (new FileInputStream (file)); JsonGenerator g2 = new TextJsonGenerator (out2); Utils.convert (p2, g2); p2.close (); g2.close (); Assert.assertEquals (out2.toString (), out1.toString ()); }
void testReader (String fileName, HashMap<String, Object> config) throws IOException { File file = new File (fileName.replace ('/', File.separatorChar)); JsonProvider provider1 = new CookJsonProvider (); JsonParserFactory f1 = provider1.createParserFactory (config); StringWriter out1 = new StringWriter (); JsonParser p1 = f1.createParser (new InputStreamReader (new FileInputStream (file), BOM.utf8)); JsonGenerator g1 = new TextJsonGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); StringWriter out2 = new StringWriter (); JsonProvider provider2 = new org.glassfish.json.JsonProviderImpl (); JsonParserFactory f2 = provider2.createParserFactory (config); JsonParser p2 = f2.createParser (new InputStreamReader (new FileInputStream (file), BOM.utf8)); JsonGenerator g2 = new TextJsonGenerator (out2); Utils.convert (p2, g2); p2.close (); g2.close (); Assert.assertEquals (out1.toString (), out2.toString ()); }
void testInputStream (String fileName, HashMap<String, Object> config) throws IOException { File file = new File (fileName.replace ('/', File.separatorChar)); JsonProvider provider1 = new CookJsonProvider (); JsonParserFactory f1 = provider1.createParserFactory (config); StringWriter out1 = new StringWriter (); JsonParser p1 = f1.createParser (new FileInputStream (file)); JsonGenerator g1 = new TextJsonGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); StringWriter out2 = new StringWriter (); JsonProvider provider2 = new org.glassfish.json.JsonProviderImpl (); JsonParserFactory f2 = provider2.createParserFactory (config); JsonParser p2 = f2.createParser (new FileInputStream (file)); JsonGenerator g2 = new TextJsonGenerator (out2); Utils.convert (p2, g2); p2.close (); g2.close (); Assert.assertEquals (out1.toString (), out2.toString ()); }
void testCharset (String fileName, HashMap<String, Object> config) throws IOException { File file = new File (fileName.replace ('/', File.separatorChar)); JsonProvider provider1 = new CookJsonProvider (); JsonParserFactory f1 = provider1.createParserFactory (config); StringWriter out1 = new StringWriter (); JsonParser p1 = f1.createParser (new FileInputStream (file), BOM.utf8); JsonGenerator g1 = new TextJsonGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); StringWriter out2 = new StringWriter (); JsonProvider provider2 = new org.glassfish.json.JsonProviderImpl (); JsonParserFactory f2 = provider2.createParserFactory (config); JsonParser p2 = f2.createParser (new FileInputStream (file), BOM.utf8); JsonGenerator g2 = new TextJsonGenerator (out2); Utils.convert (p2, g2); p2.close (); g2.close (); Assert.assertEquals (out1.toString (), out2.toString ()); }
void testFile (String f1, String f2) throws IOException { File file1 = new File (f1.replace ('/', File.separatorChar)); File file2 = new File (f2.replace ('/', File.separatorChar)); StringWriter out1 = new StringWriter (); BsonParser p1 = new BsonParser (new FileInputStream (file1)); p1.setRootAsArray (true); Assert.assertEquals (true, p1.isRootAsArray ()); TextJsonGenerator g1 = new TextJsonGenerator (out1); Utils.convert (p1, g1); p1.close (); g1.close (); StringWriter out2 = new StringWriter (); JsonProvider provider = new org.glassfish.json.JsonProviderImpl (); JsonParser p2 = provider.createParser (new FileInputStream (file2)); JsonGenerator g2 = new TextJsonGenerator (out2); Utils.convert (p2, g2); p2.close (); g2.close (); Assert.assertEquals (out1.toString (), out2.toString ()); }
private String format(final String json) { final JsonProvider provider = JsonProvider.provider(); final StringWriter out = new StringWriter(); try (final JsonReader reader = provider.createReader(new StringReader(json)); final JsonWriter jsonWriter = provider.createWriterFactory(singletonMap(JsonGenerator.PRETTY_PRINTING, true)) .createWriter(out)) { // jsonWriter.write(reader.readValue()); // bug in RI, can switch to johnzon final JsonStructure read = reader.read(); if (read.getValueType() == JsonValue.ValueType.OBJECT) { jsonWriter.writeObject(JsonObject.class.cast(read)); } else if (read.getValueType() == JsonValue.ValueType.ARRAY) { jsonWriter.writeArray(JsonArray.class.cast(read)); } else { // no reformatting return json; } return out.toString().trim(); } }
private Supplier<JsonParserFactory> createJsonParserFactory() { return new Supplier<JsonParserFactory>() { // thread safety is not mandatory private final AtomicReference<JsonParserFactory> ref = new AtomicReference<>(); @Override public JsonParserFactory get() { JsonParserFactory factory = ref.get(); if (factory == null) { factory = doCreate(); if (!ref.compareAndSet(null, factory)) { factory = ref.get(); } } return factory; } private JsonParserFactory doCreate() { return (jsonp == null ? JsonProvider.provider() : jsonp).createParserFactory(emptyMap()); } }; }
public static void format(final String content, final PrintStream out) { final JsonProvider provider = JsonProvider.provider(); try (JsonReader reader = provider.createReaderFactory(Collections.<String, Object>emptyMap()) .createReader(new ByteArrayInputStream(content.getBytes("UTF-8"))); JsonWriter writer = provider.createWriterFactory(singletonMap(JsonGenerator.PRETTY_PRINTING, "true")) .createWriter(new FilterOutputStream(out) { @Override public void close() throws IOException { super.flush(); // stdout shouldnt get closed } });) { writer.write(reader.read()); } catch (final UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
@Override public void open(final Serializable checkpoint) throws Exception { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final JsonProvider provider = this.provider == null ? JsonProvider.provider() : JsonProvider.class.cast(loader.loadClass(this.provider)); parser = provider.createParser(new FileInputStream(file)); reader = new JsonPartialReader(provider, parser); if (skipRoot == null || "true".equalsIgnoreCase(skipRoot)) { final JsonParser.Event event = parser.next(); if (event == JsonParser.Event.START_ARRAY) { end = JsonParser.Event.END_ARRAY; } else { end = JsonParser.Event.END_OBJECT; } } super.open(checkpoint); }
@Override protected TokenValidator createTokenValidator(Map<String, ?> filterConfig) throws UnavailableException { // Pass all of the filter's config to the ReaderFactory factory method. It'll ignore anything it doesn't // understand (per JSR 353). This way, clients can change the provider using the service locator and configure // the ReaderFactory using the filter's config. JsonReaderFactory jsonReaderFactory = JsonProvider.provider().createReaderFactory(filterConfig); WebKeysClient webKeysClient = HttpClientProvider.provider().createWebKeysClient(filterConfig); String audience = FilterHelper.getInitParamValue(InitParams.AUDIENCE, filterConfig); String issuer = FilterHelper.getInitParamValue(InitParams.ISSUER, filterConfig); return _jwtValidator = new JwtValidatorWithJwk(_minKidReloadTimeInSeconds, webKeysClient, audience, issuer, jsonReaderFactory); }
@Override protected TokenValidator createTokenValidator(Map<String, ?> initParams) throws UnavailableException { // Like in the OAuthJwtFilter, we'll reuse the config of this filter + the service locator to // get a JsonReaderFactory JsonReaderFactory jsonReaderFactory = JsonProvider.provider().createReaderFactory(initParams); IntrospectionClient introspectionClient = HttpClientProvider.provider() .createIntrospectionClient(initParams); return new OpaqueTokenValidator(introspectionClient, jsonReaderFactory); }
private static JsonProvider createProvider() { for (JsonProvider provider : ServiceLoader.load(JsonProvider.class)) { return provider; } throw new UnsupportedOperationException("Cannot find JsonProvider"); }
public JsonObject toJsonObject() { final JsonObjectBuilder builder = JsonProvider.provider() .createObjectBuilder(); builder.add("type", "Feature"); final JsonObjectBuilder properties = JsonProvider.provider() .createObjectBuilder(); properties.add("currentTime", getCurrentTime()); properties.add("numberOfTransfers", getNumberOfTransfers()); properties.add("numberOfThreads", getNumberOfThreads()); builder.add("properties", properties); JsonObjectBuilder geometryBuilder = JsonProvider.provider() .createObjectBuilder(); geometryBuilder.add("type", "LineString"); JsonArrayBuilder coordinatesBuilder = JsonProvider.provider() .createArrayBuilder(); for (int index = 0; index < getPointList().size(); index++) { JsonArrayBuilder coordinateBuilder = JsonProvider.provider() .createArrayBuilder(); coordinateBuilder.add(getPointList().getLon(index)); coordinateBuilder.add(getPointList().getLat(index)); coordinatesBuilder.add(coordinateBuilder.build()); } geometryBuilder.add("coordinates", coordinatesBuilder.build()); builder.add("geometry", geometryBuilder.build()); return builder.build(); }
@Override public JsonArray convert(List<Double> value) { Validate.noNullElements(value); Validate.isTrue(value.size() == 2); final JsonArrayBuilder builder = JsonProvider.provider() .createArrayBuilder(); builder.add(value.get(1)); builder.add(value.get(0)); return builder.build(); }
@Override public JsonObject convert(RailwayNode value) { final JsonObjectBuilder builder = JsonProvider.provider() .createObjectBuilder(); builder.add("type", "Feature"); builder.add("geometry", DoublesToPointGeometryJsonObjectConverter.INSTANCE .convert(value.getCoordinates())); final JsonObjectBuilder properties = JsonProvider.provider() .createObjectBuilder(); properties.add("id", value.getId()); properties.add("formOfNode", value.getFormOfNode()); final String geographicalName = value.getGeographicalName(); if (geographicalName != null) { properties.add("name", geographicalName); } else { properties.addNull("name"); } properties.add("sLinkIds", StringsToJsonArrayConverter.INSTANCE .convert(value.getSpokeStartIds())); properties.add("eLinkIds", StringsToJsonArrayConverter.INSTANCE .convert(value.getSpokeEndIds())); builder.add("properties", properties); return builder.build(); }
@Override public JsonArray convert(Iterable<String> value) { final JsonArrayBuilder builder = JsonProvider.provider() .createArrayBuilder(); for (String item : value) { builder.add(item); } return builder.build(); }
@Override public JsonObject convert(List<Double> value) { final JsonObjectBuilder builder = JsonProvider.provider() .createObjectBuilder(); builder.add("type", "LineString"); builder.add("coordinates", DoublesToLineStringGeometryJsonArrayConverter.INSTANCE .convert(value)); return builder.build(); }
@Override public JsonArray convert(List<Double> value) { Validate.noNullElements(value); Validate.isTrue((value.size() % 2) == 0); final JsonArrayBuilder builder = JsonProvider.provider() .createArrayBuilder(); for (int index = 0; index < value.size(); index += 2) { builder.add(DoublesToPointGeometryJsonArrayConverter.INSTANCE .convert(value.subList(index, index + 2))); } return builder.build(); }
@Override public JsonObject convert(RailwayStationNode value) { final JsonObjectBuilder builder = JsonProvider.provider() .createObjectBuilder(); builder.add("type", "Feature"); builder.add("geometry", DoublesToPointGeometryJsonObjectConverter.INSTANCE .convert(value.getCoordinates())); final JsonObjectBuilder properties = JsonProvider.provider() .createObjectBuilder(); properties.add("id", value.getId()); properties.add("formOfNode", value.getFormOfNode()); properties.add("code", value.getRailwayStationCode() .getStationCode()); properties.add("name", value.getGeographicalName()); properties.add("sLinkIds", StringsToJsonArrayConverter.INSTANCE .convert(value.getSpokeStartIds())); properties.add("eLinkIds", StringsToJsonArrayConverter.INSTANCE .convert(value.getSpokeEndIds())); builder.add("properties", properties); return builder.build(); }
@Override public JsonObject convert(List<Double> value) { final JsonObjectBuilder builder = JsonProvider.provider() .createObjectBuilder(); builder.add("type", "Point"); builder.add("coordinates", DoublesToPointGeometryJsonArrayConverter.INSTANCE .convert(value)); return builder.build(); }
@Override public JsonObject convert(RailwayLink value) { final JsonObjectBuilder builder = JsonProvider.provider() .createObjectBuilder(); builder.add("type", "Feature"); builder.add("geometry", DoublesToLineStringGeometryJsonObjectConverter.INSTANCE .convert(value.getCoordinates())); final JsonObjectBuilder properties = JsonProvider.provider() .createObjectBuilder(); properties.add("id", value.getId()); final String startNodeId = value.getStartNodeId(); if (startNodeId != null) { properties.add("sNodeId", startNodeId); } else { properties.addNull("sNodeId"); } final String endNodeId = value.getEndNodeId(); if (endNodeId != null) { properties.add("eNodeId", endNodeId); } else { properties.addNull("eNodeId"); } properties.add("lineId", value.getRailwayLineId()); properties.add("lineCode", value.getRailwayLineCode()); properties.add("lineName", value.getRailwayLineGeographicalName()); properties.add("linkSeqId", value.getRailwayLinkSequenceId()); builder.add("properties", properties); return builder.build(); }
@Override public JsonObject convert(RailwayLine value) { final JsonObjectBuilder builder = JsonProvider.provider() .createObjectBuilder(); builder.add("type", "Feature"); final JsonObjectBuilder properties = JsonProvider.provider() .createObjectBuilder(); properties.add("id", value.getId()); properties.add("name", value.getGeographicalName()); properties.add("code", value.getRailwayLineCode()); final JsonArrayBuilder railwayLinkIdsBuilder = JsonProvider.provider() .createArrayBuilder(); for (String railwayLinkId : value.getRailwayLinkIds()) { railwayLinkIdsBuilder.add(railwayLinkId); } properties.add("linkIds", railwayLinkIdsBuilder.build()); builder.add("properties", properties); JsonObjectBuilder geometryBuilder = JsonProvider.provider() .createObjectBuilder(); geometryBuilder.add("type", "MultiLineString"); JsonArrayBuilder coordinatesBuilder = JsonProvider.provider() .createArrayBuilder(); for (RailwayLink railwayLink : value.getRailwayLinks()) { coordinatesBuilder .add(DoublesToLineStringGeometryJsonArrayConverter.INSTANCE .convert(railwayLink.getCoordinates())); } geometryBuilder.add("coordinates", coordinatesBuilder.build()); builder.add("geometry", geometryBuilder.build()); return builder.build(); }