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:com.basho.riak.client.query.MapReduce.java
/** * Creates the JSON string of the M/R job for submitting to the * {@link RawClient}/* www . ja va 2s .com*/ * * Uses Jackson to write out the JSON string. I'm not very happy with this * method, it is a candidate for change. * * TODO re-evaluate this method, look for something smaller and more elegant. * * @return a String of JSON * @throws RiakException * if, for some reason, we can't create a JSON string. */ private String writeSpec() throws RiakException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { JsonGenerator jg = new JsonFactory().createJsonGenerator(out, JsonEncoding.UTF8); jg.setCodec(new ObjectMapper()); jg.writeStartObject(); jg.writeFieldName("inputs"); writeInput(jg); jg.writeFieldName("query"); jg.writeStartArray(); writePhases(jg); jg.writeEndArray(); if (timeout != null) { jg.writeNumberField("timeout", timeout); } jg.writeEndObject(); jg.flush(); return out.toString("UTF8"); } catch (IOException e) { throw new RiakException(e); } }
From source file:com.cedarsoft.serialization.jackson.AbstractJacksonSerializer.java
@Override public void serialize(@Nonnull T object, @WillNotClose @Nonnull OutputStream out) throws IOException { JsonFactory jsonFactory = JacksonSupport.getJsonFactory(); JsonGenerator generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8); serialize(object, generator);//from ww w .j a v a 2 s. com generator.flush(); }
From source file:org.lockss.crawljax.TestRequestResponse.java
public void testToJson() throws Exception { File outFile = new File("test.json"); outFile.deleteOnExit();/*from w w w . j a va 2s. c om*/ JsonGenerator generator = factory.createGenerator(outFile, JsonEncoding.UTF8); AjaxRequestResponse.toJson(generator, mReqResp); generator.flush(); generator.close(); Request req = mReqResp.getRequest(); Response resp = mReqResp.getResponse(); // load it in and check ObjectMapper mapper = new ObjectMapper(); AjaxRequestResponse rr = mapper.readValue(outFile, AjaxRequestResponse.class); // same request data AjaxRequestResponse.Request rr_req = rr.getRequest(); AjaxRequestResponse.Response rr_resp = rr.getResponse(); assertEquals(rr_req.getMethod(), req.getMethod()); assertEquals(rr_req.getUrl(), req.getUrl()); assertEquals(rr_req.getVersion(), req.getVersion()); // same response data assertEquals(rr_resp.getMessage(), resp.getMessage()); assertEquals(rr_resp.getStatus(), resp.getStatus()); assertEquals(new String(rr_resp.getContent()), new String(resp.getContent())); }
From source file:ru.histone.HistoneOptimizeAstMojo.java
public void execute() throws MojoExecutionException { try {//from w w w . ja va2 s .c o m getLog().info(MessageFormat.format("Running DirectoryScanner with params: baseDir={0}, includes=[{1}]", baseDir, StringUtils.join(includes, ", "))); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(baseDir); scanner.setIncludes(includes); scanner.scan(); List<OptimizationTypes> optimizationTypeses = new ArrayList<OptimizationTypes>(); for (String optimizationType : optimizationTypes) { optimizationTypeses.add(OptimizationTypes.valueOf(optimizationType)); } OptimizationTypes[] array = optimizationTypeses .toArray(new OptimizationTypes[optimizationTypeses.size()]); getLog().info(MessageFormat.format("Optimizations to be run: [{0}]", "" + StringUtils.join(optimizationTypes, ", "))); String[] includedFiles = scanner.getIncludedFiles(); getLog().info(MessageFormat.format("Files found:\n{0}", StringUtils.join(includedFiles, "\n"))); HistoneBuilder builder = new HistoneBuilder(); Histone histone = builder.build(); ObjectMapper jackson = new ObjectMapper(); JsonFactory jsonFactory = new JsonFactory(); for (String includedFile : includedFiles) { ArrayNode ast = histone.parseTemplateToAST(new FileReader(new File(baseDir, includedFile))); ObjectNode context = builder.getNodeFactory().jsonObject(); int astCount1 = ASTTreeElementsCounter.count(ast); ArrayNode optimizedAst = histone.optimizeAST(ast, context, array); int astCount2 = ASTTreeElementsCounter.count(ast); getLog().info(MessageFormat.format("Processing {0}, before: {1}, after: {2}", includedFile, astCount1, astCount2)); JsonGenerator jsonGenerator = jsonFactory.createGenerator(new File(baseDir, includedFile + ".ast"), JsonEncoding.UTF8); jackson.writeTree(jsonGenerator, optimizedAst); } } catch (Exception e) { throw new MojoExecutionException("Error parsing templates to AST", e); } }
From source file:sys.core.jackson.MappingJacksonHttpMessageConverter.java
protected JsonEncoding getJsonEncoding(MediaType contentType) { if (contentType != null && contentType.getCharSet() != null) { Charset charset = contentType.getCharSet(); for (JsonEncoding encoding : JsonEncoding.values()) { if (charset.name().equals(encoding.getJavaName())) { return encoding; }/* w w w . j a va 2 s .c o m*/ } } return JsonEncoding.UTF8; }
From source file:org.ojai.json.impl.JsonDocumentBuilder.java
private void initJsonGenerator(OutputStream out) { try {//from w w w . jav a 2s . co m JsonFactory jFactory = new JsonFactory(); jsonGenerator = jFactory.createGenerator(out, JsonEncoding.UTF8); ctxStack = new Stack<ContainerContext>(); currentContext = ContainerContext.NULL; checkContext = true; setJsonOptions(JsonOptions.WITH_TAGS); } catch (IOException ie) { throw transformIOException(ie); } }
From source file:com.basho.riak.client.api.commands.mapreduce.MapReduce.java
/** * Creates the JSON string of the M/R job for submitting to the client * <p/>/*from w w w .j a v a 2s . co m*/ * Uses Jackson to write out the JSON string. I'm not very happy with this method, it is a candidate for change. * <p/> * TODO re-evaluate this method, look for something smaller and more elegant. * * @return a String of JSON * @throws RiakException if, for some reason, we can't create a JSON string. */ String writeSpec() throws RiakException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { JsonGenerator jg = new JsonFactory().createGenerator(out, JsonEncoding.UTF8); ObjectMapper objectMapper = new ObjectMapper(); SimpleModule specModule = new SimpleModule("SpecModule", Version.unknownVersion()); specModule.addSerializer(LinkPhase.class, new LinkPhaseSerializer()); specModule.addSerializer(FunctionPhase.class, new FunctionPhaseSerializer()); specModule.addSerializer(BucketInput.class, new BucketInputSerializer()); specModule.addSerializer(SearchInput.class, new SearchInputSerializer()); specModule.addSerializer(BucketKeyInput.class, new BucketKeyInputSerializer()); specModule.addSerializer(IndexInput.class, new IndexInputSerializer()); objectMapper.registerModule(specModule); jg.setCodec(objectMapper); List<MapReducePhase> phases = spec.getPhases(); phases.get(phases.size() - 1).setKeep(true); jg.writeObject(spec); jg.flush(); return out.toString("UTF8"); } catch (IOException e) { throw new RiakException(e); } }
From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.technical.system.OSInstanceJSON.java
public final static void manyOSInstances2JSON(HashSet<OSInstance> osInstances, ByteArrayOutputStream outStream) throws IOException { JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8); jgenerator.writeStartObject();/*from ww w . j a va2s. com*/ jgenerator.writeArrayFieldStart("osInstances"); Iterator<OSInstance> iter = osInstances.iterator(); while (iter.hasNext()) { OSInstance current = iter.next(); OSInstanceJSON.osInstance2JSON(current, jgenerator); } jgenerator.writeEndArray(); jgenerator.writeEndObject(); jgenerator.close(); }
From source file:com.cedarsoft.serialization.jackson.NumberSerializerTest.java
@Test public void testDouble2() throws Exception { JsonFactory jsonFactory = JacksonSupport.getJsonFactory(); ByteArrayOutputStream out = new ByteArrayOutputStream(); JsonGenerator generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8); getSerializer().serialize(generator, 11133.0, Version.valueOf(1, 0, 0)); generator.close();/*from w w w. j a v a2 s . co m*/ JsonUtils.assertJsonEquals("11133.0", out.toString()); }
From source file:com.meetingninja.csse.database.MeetingDatabaseAdapter.java
private static String getEditPayload(String meetingID, String field, String value) throws IOException { ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object for Title jgen.writeStartObject();//from w ww. j a va2 s . c o m jgen.writeStringField(Keys.Meeting.ID, meetingID); jgen.writeStringField("field", field); jgen.writeStringField("value", value); jgen.writeEndObject(); jgen.close(); String payload = json.toString("UTF8"); ps.close(); return payload; }