Example usage for com.fasterxml.jackson.core JsonEncoding UTF8

List of usage examples for com.fasterxml.jackson.core JsonEncoding UTF8

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonEncoding UTF8.

Prototype

JsonEncoding UTF8

To view the source code for com.fasterxml.jackson.core JsonEncoding UTF8.

Click Source Link

Usage

From source file:com.turn.splicer.ConfigServlet.java

private void doGetWork(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("application/json");
    JsonGenerator generator = new JsonFactory().createGenerator(response.getOutputStream(), JsonEncoding.UTF8);
    Config.get().writeAsJson(generator);
    generator.close();/*w w w  .  jav a2  s .  c  o  m*/
}

From source file:org.jongo.marshall.jackson.bson4jackson.MongoBsonFactory.java

@Override
public BsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException {

    IOContext ctxt = _createContext(out, true);
    ctxt.setEncoding(enc);/*from   w  w w .  ja v  a  2s. c o m*/
    if (enc == JsonEncoding.UTF8 && _outputDecorator != null) {
        out = _outputDecorator.decorate(ctxt, out);
    }
    BsonGenerator g = new MongoBsonGenerator(_generatorFeatures, _bsonGeneratorFeatures, out);
    ObjectCodec codec = getCodec();
    if (codec != null) {
        g.setCodec(codec);
    }
    if (_characterEscapes != null) {
        g.setCharacterEscapes(_characterEscapes);
    }
    return g;

}

From source file:org.mashti.jetson.json.JsonResponseEncoder.java

JsonResponseEncoder(final JsonFactory json_factory) {

    this(json_factory, JsonEncoding.UTF8);
}

From source file:org.example.testcases.BasicTypesSerializer.java

public void serialize(OutputStream outputStream, BasicTypes basicTypes) throws IOException {
    try (JsonGenerator jg = jsonFactory.createGenerator(outputStream, JsonEncoding.UTF8)) {
        writeObject(jg, basicTypes);/*from w  w w. j  a  v a 2 s  .  c  o  m*/
    }
}

From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.technical.system.OSTypeJSON.java

public final static void oneOSType2JSON(OSType osType, ByteArrayOutputStream outStream) throws IOException {
    JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8);
    OSTypeJSON.osType2JSON(osType, jgenerator);
    jgenerator.close();/*from w w w .j av a2s.c o m*/
}

From source file:org.example.testcases.BasicTypeArraysSerializer.java

public void serialize(OutputStream outputStream, BasicTypeArrays basicTypeArrays) throws IOException {
    try (JsonGenerator jg = jsonFactory.createGenerator(outputStream, JsonEncoding.UTF8)) {
        writeObject(jg, basicTypeArrays);
    }//from  w ww  .jav  a  2s .  c o m
}

From source file:com.proofpoint.event.client.TestJsonEventSerializer.java

@Test(expectedExceptions = InvalidEventException.class)
public void testUnregisteredEventClass() throws Exception {
    JsonEventSerializer eventSerializer = new JsonEventSerializer(new NodeInfo("test"), DummyEventClass.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonGenerator jsonGenerator = new JsonFactory().createGenerator(out, JsonEncoding.UTF8);

    FixedDummyEventClass event = TestingUtils.getEvents().get(0);
    eventSerializer.serialize(event, "sample-trace-token", jsonGenerator);
}

From source file:com.meetingninja.csse.database.GroupDatabaseAdapter.java

public static Group createGroup(Group g) throws IOException, MalformedURLException {
    // Server URL setup
    String _url = getBaseUri().build().toString();

    // establish connection
    URL url = new URL(_url);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    conn.setRequestMethod("POST");
    addRequestHeader(conn, true);/*  w  w w  .  ja v a  2s.  co m*/

    // prepare POST payload
    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
    jgen.writeStartObject();
    jgen.writeStringField(Keys.Group.TITLE, g.getGroupTitle());
    jgen.writeArrayFieldStart(Keys.Group.MEMBERS);
    for (User member : g.getMembers()) {
        jgen.writeStartObject();
        jgen.writeStringField(Keys.User.ID, member.getID());
        jgen.writeEndObject();

    }
    jgen.writeEndArray();
    jgen.writeEndObject();
    jgen.close();

    // Get JSON Object payload from print stream
    String payload = json.toString("UTF8");
    ps.close();

    // send payload
    int responseCode = sendPostPayload(conn, payload);
    String response = getServerResponse(conn);

    // prepare to get the id of the created Meeting
    // Map<String, String> responseMap = new HashMap<String, String>();

    /*
     * result should get valid={"meetingID":"##"}
     */
    String result = new String();
    if (!response.isEmpty()) {
        // responseMap = MAPPER.readValue(response,
        // new TypeReference<HashMap<String, String>>() {
        // });
        JsonNode groupNode = MAPPER.readTree(response);
        if (!groupNode.has(Keys.Group.ID)) {
            result = "invalid";
        } else
            result = groupNode.get(Keys.Group.ID).asText();
    }

    if (!result.equalsIgnoreCase("invalid"))
        g.setID(result);

    conn.disconnect();
    return g;
}

From source file:io.airlift.event.client.JsonEventWriter.java

public <T> void writeEvents(EventClient.EventGenerator<T> events, OutputStream out) throws IOException {
    Preconditions.checkNotNull(events, "events is null");
    Preconditions.checkNotNull(out, "out is null");

    final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);

    jsonGenerator.writeStartArray();/*from ww  w. ja  va2 s .c  om*/

    events.generate(new EventClient.EventPoster<T>() {
        @Override
        public void post(T event) throws IOException {
            JsonSerializer<T> serializer = getSerializer(event);
            if (serializer == null) {
                throw new InvalidEventException("Event class [%s] has not been registered as an event",
                        event.getClass().getName());
            }

            serializer.serialize(event, jsonGenerator, null);
        }
    });

    jsonGenerator.writeEndArray();
    jsonGenerator.flush();
}

From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.organisational.CompanyJSON.java

public final static void oneCompany2JSON(Company company, ByteArrayOutputStream outStream) throws IOException {
    JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8);
    CompanyJSON.company2JSON(company, jgenerator);
    jgenerator.close();/*from   w ww  .j  av  a 2s.  c om*/
}