List of usage examples for com.fasterxml.jackson.core JsonEncoding UTF8
JsonEncoding UTF8
To view the source code for com.fasterxml.jackson.core JsonEncoding UTF8.
Click Source Link
From source file:org.graylog2.gelfclient.encoder.GelfMessageJsonEncoderTest.java
@Test(expectedExceptions = EncoderException.class) public void testExceptionIsPassedThrough() throws Exception { final JsonFactory jsonFactory = mock(JsonFactory.class); when(jsonFactory.createGenerator(any(OutputStream.class), eq(JsonEncoding.UTF8))) .thenThrow(new IOException()); final EmbeddedChannel channel = new EmbeddedChannel(new GelfMessageJsonEncoder(jsonFactory)); assertTrue(channel.writeOutbound(new GelfMessage("test"))); }
From source file:com.sdl.odata.renderer.json.writer.JsonServiceDocumentWriter.java
/** * The main method for Writer.//from w ww . j av a 2 s . com * It builds the service root document according to spec. * * @return output in json * @throws ODataRenderException If unable to render the json service document */ public String buildJson() throws ODataRenderException { LOG.debug("Start building Json service root document"); try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(stream, JsonEncoding.UTF8); jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(CONTEXT, getContextURL(uri, entityDataModel)); jsonGenerator.writeArrayFieldStart(VALUE); List<EntitySet> entities = entityDataModel.getEntityContainer().getEntitySets(); for (EntitySet entity : entities) { if (entity.isIncludedInServiceDocument()) { writeObject(jsonGenerator, entity); } } List<Singleton> singletons = entityDataModel.getEntityContainer().getSingletons(); for (Singleton singleton : singletons) { writeObject(jsonGenerator, singleton); } jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); jsonGenerator.close(); return stream.toString(StandardCharsets.UTF_8.name()); } catch (IOException e) { throw new ODataRenderException("It is unable to render service document", e); } }
From source file:org.graylog2.gelfclient.encoder.GelfMessageJsonEncoder.java
private byte[] toJson(final GelfMessage message) throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); try (final JsonGenerator jg = jsonFactory.createGenerator(out, JsonEncoding.UTF8)) { jg.writeStartObject();// w ww .j a v a 2 s . co m jg.writeStringField("version", message.getVersion().toString()); jg.writeNumberField("timestamp", message.getTimestamp()); jg.writeStringField("host", message.getHost()); jg.writeStringField("short_message", message.getMessage()); if (message.getLevel() != null) { jg.writeNumberField("level", message.getLevel().getNumericLevel()); } if (null != message.getFullMessage()) { jg.writeStringField("full_message", message.getFullMessage()); } for (Map.Entry<String, Object> field : message.getAdditionalFields().entrySet()) { final String realKey = field.getKey().startsWith("_") ? field.getKey() : ("_" + field.getKey()); if (field.getValue() instanceof Number) { // Let Jackson figure out how to write Number values. jg.writeObjectField(realKey, field.getValue()); } else if (field.getValue() == null) { jg.writeNullField(realKey); } else { jg.writeStringField(realKey, field.getValue().toString()); } } jg.writeEndObject(); } return out.toByteArray(); }
From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.technical.network.RoutingAreaJSON.java
public final static void manyRoutingAreas2JSON(HashSet<RoutingArea> routingAreas, ByteArrayOutputStream outStream) throws IOException { JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8); jgenerator.writeStartObject();/*from www . ja v a2s. c o m*/ jgenerator.writeArrayFieldStart("routingAreas"); Iterator<RoutingArea> iter = routingAreas.iterator(); while (iter.hasNext()) { RoutingArea current = iter.next(); RoutingAreaJSON.routingArea2JSON(current, jgenerator); } jgenerator.writeEndArray(); jgenerator.writeEndObject(); jgenerator.close(); }
From source file:com.buildria.mocking.serializer.JacksonJsonSerializer.java
private JsonEncoding mappingFrom(Charset charset) { if (StandardCharsets.UTF_8.equals(charset)) { return JsonEncoding.UTF8; }/*from w w w . j ava2s.c om*/ if (StandardCharsets.UTF_16BE.equals(charset)) { return JsonEncoding.UTF16_BE; } if (StandardCharsets.UTF_16LE.equals(charset)) { return JsonEncoding.UTF16_LE; } if (Charset.forName("UTF-32BE").equals(charset)) { return JsonEncoding.UTF32_BE; } if (Charset.forName("UTF-32LE").equals(charset)) { return JsonEncoding.UTF32_LE; } throw new MockingException("No charset found. " + charset.toString()); }
From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.organisational.ApplicationJSON.java
public final static void manyApplications2JSON(HashSet<Application> applications, ByteArrayOutputStream outStream) throws IOException { JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8); jgenerator.writeStartObject();//from www. j a v a 2s .c o m jgenerator.writeArrayFieldStart("applications"); Iterator<Application> iterC = applications.iterator(); while (iterC.hasNext()) { Application current = iterC.next(); ApplicationJSON.application2JSON(current, jgenerator); } jgenerator.writeEndArray(); jgenerator.writeEndObject(); jgenerator.close(); }
From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.technical.network.DatacenterJSON.java
public final static void oneDatacenter2JSON(Datacenter datacenter, ByteArrayOutputStream outStream) throws IOException { JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8); DatacenterJSON.datacenter2JSON(datacenter, jgenerator); jgenerator.close();/*from w w w. j a v a 2 s . com*/ }
From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.technical.network.SubnetJSON.java
public final static void manySubnets2JSON(HashSet<Subnet> subnets, ByteArrayOutputStream outStream) throws IOException { JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8); jgenerator.writeStartObject();/* www.j ava 2 s.co m*/ jgenerator.writeArrayFieldStart("subnets"); Iterator<Subnet> iter = subnets.iterator(); while (iter.hasNext()) { Subnet current = iter.next(); SubnetJSON.subnet2JSON(current, jgenerator); } jgenerator.writeEndArray(); jgenerator.writeEndObject(); jgenerator.close(); }
From source file:nl.bneijt.javapjson.JavapJsonMojo.java
public void execute() throws MojoExecutionException { JsonFactory jsonFactory = new JsonFactory(); if (!outputDirectory.exists()) { throw new MojoExecutionException( "No build output directory found. Was looking at \"" + outputDirectory + "\""); }//from www .ja va2 s. c o m String jsonDirectory = buildDirectory.getPath() + File.separator + "javap-json"; File jsonDirectoryFile = new File(jsonDirectory); if (!jsonDirectoryFile.exists()) { if (!jsonDirectoryFile.mkdir()) { throw new MojoExecutionException( "Could not create output directory \"" + jsonDirectoryFile.getPath() + "\""); } getLog().debug("Created output directory \"" + jsonDirectoryFile.getPath() + "\""); } for (File classFile : FileUtils.listFiles(outputDirectory, new SuffixFileFilter(CLASS_EXTENSION), TrueFileFilter.INSTANCE)) { String output = runJavap(classFile); JavapLOutput parseL = JavapParser.parseL(output); File outputFile = new File(jsonDirectory + File.separator + "current.json"); try { JsonGenerator jsonOutput = jsonFactory.createJsonGenerator(outputFile, JsonEncoding.UTF8); parseL.toJsonOnto(jsonOutput); //Move file into correct position File classDirectory = classFile.getParentFile(); String classFileName = classFile.getName(); String restOfDirectory = classDirectory.getPath().substring(outputDirectory.getPath().length()); File jsonOutputFileDirectory = new File(jsonDirectory + restOfDirectory); File jsonOutputFile = new File(jsonOutputFileDirectory.getPath() + File.separator + classFileName.substring(0, classFileName.length() - ".class".length()) + ".json"); if (!jsonOutputFileDirectory.exists()) FileUtils.forceMkdir(jsonOutputFileDirectory); if (jsonOutputFile.exists()) { FileUtils.deleteQuietly(jsonOutputFile); } FileUtils.moveFile(outputFile, jsonOutputFile); } catch (IOException e) { // TODO Auto-generated catch block throw new MojoExecutionException("Unable to serialize javap output to Json", e); } } }
From source file:com.cedarsoft.couchdb.io.ViewResponseSerializer.java
public <K, V> void serialize(@Nonnull ViewResponse<K, V, ?> viewResponse, @Nonnull JacksonSerializer<? super K> keySerializer, @Nonnull JacksonSerializer<? super V> valueSerializer, @Nonnull OutputStream out) throws IOException { JsonFactory jsonFactory = JacksonSupport.getJsonFactory(); JsonGenerator generator = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8); generator.writeStartObject();//from ww w.j av a2 s . co m generator.writeNumberField(PROPERTY_TOTAL_ROWS, viewResponse.getTotalRows()); generator.writeNumberField(PROPERTY_OFFSET, viewResponse.getOffset()); //Now the rows generator.writeFieldName(PROPERTY_ROWS); generator.writeStartArray(); for (Row<K, V, ?> row : viewResponse.getRows()) { rowSerializer.serialize(row, keySerializer, valueSerializer, generator); } generator.writeEndArray(); generator.writeEndObject(); generator.close(); }