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.cedarsoft.couchdb.io.ActionResponseSerializerTest.java

License:asdf

/**
 * Only used for tests/*from  w  w w .  jav  a  2 s. c  om*/
 * @param object
 * @param out
 * @throws IOException
 */
@Deprecated
public static void serialize(@Nonnull ActionResponse object, @Nonnull OutputStream out) throws IOException {
    JsonFactory jsonFactory = JacksonSupport.getJsonFactory();

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

    generator.writeStartObject();

    serialize(generator, object);
    generator.writeEndObject();

    generator.close();
}

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

public final static void manyDatacenters2JSON(HashSet<Datacenter> datacenters, ByteArrayOutputStream outStream)
        throws IOException {
    JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8);
    jgenerator.writeStartObject();//  w ww  .  ja  v  a  2s .  c o m
    jgenerator.writeArrayFieldStart("datacenters");
    Iterator<Datacenter> iter = datacenters.iterator();
    while (iter.hasNext()) {
        Datacenter current = iter.next();
        DatacenterJSON.datacenter2JSON(current, jgenerator);
    }
    jgenerator.writeEndArray();
    jgenerator.writeEndObject();
    jgenerator.close();
}

From source file:com.cedarsoft.serialization.jackson.NumberSerializerTest.java

@Test
public void testInt() throws Exception {
    JsonFactory jsonFactory = JacksonSupport.getJsonFactory();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonGenerator generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8);

    getSerializer().serialize(generator, 11133, Version.valueOf(1, 0, 0));

    generator.close();//from  www. ja  va 2s .c  om
    JsonUtils.assertJsonEquals("11133", out.toString());
}

From source file:com.github.ljtfreitas.restify.http.client.message.converter.json.JacksonMessageConverter.java

@Override
public void write(T body, HttpRequestMessage httpRequestMessage) throws RestifyHttpMessageWriteException {
    try {//from  w ww  .  j  a  va 2  s  .co  m
        JsonEncoding encoding = Arrays.stream(JsonEncoding.values())
                .filter(e -> e.getJavaName().equals(httpRequestMessage.charset())).findFirst()
                .orElse(JsonEncoding.UTF8);

        JsonGenerator generator = objectMapper.getFactory().createGenerator(httpRequestMessage.output(),
                encoding);

        objectMapper.writeValue(generator, body);
        generator.flush();

    } catch (IOException e) {
        throw new RestifyHttpMessageWriteException(e);
    }

}

From source file:com.cedarsoft.serialization.jackson.IntegerSerializerTest.java

@Test
public void testIt() throws Exception {
    JsonFactory jsonFactory = JacksonSupport.getJsonFactory();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonGenerator generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8);

    getSerializer().serialize(generator, 12, Version.valueOf(1, 0, 0));

    generator.close();//from  w w w. j  a  v  a 2 s .  c om
    JsonUtils.assertJsonEquals("12", out.toString());
}

From source file:com.cedarsoft.serialization.jackson.StringSerializerTest.java

License:asdf

@Test
public void testIt() throws Exception {
    JsonFactory jsonFactory = JacksonSupport.getJsonFactory();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonGenerator generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8);

    getSerializer().serialize(generator, "asdf", Version.valueOf(1, 0, 0));

    generator.close();/*ww  w. j a  va2  s  . c om*/
    JsonUtils.assertJsonEquals("\"asdf\"", out.toString());
}

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

public static JsonNode update(String agendaID, Map<String, String> key_values)
        throws JsonGenerationException, IOException, InterruptedException {
    // 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);
    for (String key : key_values.keySet()) {
        jgen.flush();/*from   w  ww .j a v  a  2 s .co  m*/
        // Build JSON Object
        jgen.writeStartObject();
        jgen.writeStringField(Keys.Agenda.ID, agendaID);
        jgen.writeStringField("field", key);
        jgen.writeStringField("value", key_values.get(key));
        jgen.writeEndObject();
        jgen.writeRaw("\f"); // write a form-feed to separate the payloads
    }

    jgen.close();
    // Get JSON Object payload from print stream
    String payload = json.toString("UTF8");
    ps.close();
    // The backend can only update a single field at a time
    String[] payloads = payload.split("\f\\s*"); // split at each form-feed
    Thread t = new Thread(new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.getLocalizedMessage();
            }
        }
    }));
    String response = "";
    for (String p : payloads) {
        t.run();
        response = updateHelper(p);
    }
    return MAPPER.readTree(response);
}

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

public static String login(String email, String pass) throws IOException {
    // Server URL setup
    String _url = getBaseUri().appendPath("Login").build().toString();
    // Establish connection
    URL url = new URL(_url);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    // add request header
    conn.setRequestMethod(IRequest.POST);
    addRequestHeader(conn, true);/*w w  w. java  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);

    try {
        // hash the password
        pass = Utilities.computeHash(pass);
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, e.getLocalizedMessage());
    }
    // Build JSON Object
    jgen.writeStartObject();
    jgen.writeStringField(Keys.User.EMAIL, email);
    jgen.writeStringField("password", pass);
    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);

    /*
     * result should get valid={"userID":"##"}
     * invalid={"errorID":"3","errorMessage":"invalid username or password"}
     */
    String result = "";
    if (!response.isEmpty()) {
        JsonNode tree = MAPPER.readTree(response);
        if (!tree.has(Keys.User.ID)) {
            logError(TAG, tree);
            result = "invalid username or password";
        } else
            result = tree.get(Keys.User.ID).asText();
    }

    conn.disconnect();
    return result;

}

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

public <T> void writeEvents(EventGenerator<T> events, @Nullable final String token, OutputStream out)
        throws IOException {
    checkNotNull(events, "events is null");
    checkNotNull(out, "out is null");

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

    jsonGenerator.writeStartArray();/*from w  w  w.  j  a  v a 2  s. co  m*/

    events.generate(new EventClient.EventPoster<T>() {
        @Override
        public void post(T event) throws IOException {
            JsonSerializer<T> serializer = getSerializer(event, token);
            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();
}