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:net.echinopsii.ariane.community.core.directory.wat.json.ds.technical.system.OSTypeJSON.java

public final static void manyOSTypes2JSON(HashSet<OSType> osTypes, ByteArrayOutputStream outStream)
        throws IOException {
    JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8);
    jgenerator.writeStartObject();/*  ww w . ja  v  a 2  s  .  com*/
    jgenerator.writeArrayFieldStart("osTypes");
    Iterator<OSType> iter = osTypes.iterator();
    while (iter.hasNext()) {
        OSType current = iter.next();
        OSTypeJSON.osType2JSON(current, jgenerator);
    }
    jgenerator.writeEndArray();
    jgenerator.writeEndObject();
    jgenerator.close();
}

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

@Before
public void setUp() throws Exception {
    jsonFactory = JacksonSupport.getJsonFactory();
    out = new ByteArrayOutputStream();
    generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8);
}

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

public static Project createProject(Project p) 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  .j  a v  a  2  s  . 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.Project.TITLE, p.getProjectTitle());
    jgen.writeArrayFieldStart(Keys.Project.MEETINGS);
    for (Meeting meeting : p.getMeetings()) {
        jgen.writeStartObject();
        jgen.writeStringField(Keys.Meeting.ID, meeting.getID());
        jgen.writeEndObject();

    }
    jgen.writeEndArray();
    jgen.writeArrayFieldStart(Keys.Project.NOTES);
    for (Note note : p.getNotes()) {
        jgen.writeStartObject();
        jgen.writeStringField(Keys.Note.ID, note.getID());
        jgen.writeEndObject();

    }
    jgen.writeEndArray();
    jgen.writeArrayFieldStart(Keys.Project.MEMBERS);
    for (User member : p.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
    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 projectNode = MAPPER.readTree(response);
        if (!projectNode.has(Keys.Project.ID)) {
            result = "invalid";
        } else
            result = projectNode.get(Keys.Project.ID).asText();
    }

    if (!result.equalsIgnoreCase("invalid"))
        p.setProjectID(result);

    conn.disconnect();
    return p;
}

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

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

    NullSerializer serializer = getSerializer();
    serializer.serialize(generator, null, Version.valueOf(1, 0, 0));
    generator.close();/*w  ww .  ja  v  a2 s  .  co m*/
    JsonUtils.assertJsonEquals("null", out.toString());

    assertNull(serializer.deserialize(new ByteArrayInputStream(out.toByteArray())));
}

From source file:net.echinopsii.ariane.community.plugin.rabbitmq.directory.json.RabbitmqNodeJSON.java

public final static void oneRabbitmqNode2JSON(RabbitmqNode node, ByteArrayOutputStream outStream)
        throws IOException {
    JsonGenerator jgenerator = RabbitmqDirectoryBootstrap.getjFactory().createGenerator(outStream,
            JsonEncoding.UTF8);
    rabbitmqNode2JSON(node, jgenerator);
    jgenerator.close();//from   w  w  w.  ja  va 2 s  .c  o  m
}

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

public <T> Writer createEventWriter(final Iterator<T> eventIterator, final String token, final OutputStream out)
        throws IOException {
    checkNotNull(eventIterator, "eventIterator is null");
    checkNotNull(out, "out is null");

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

    jsonGenerator.writeStartArray();/*from  www .j  av  a2 s  . c o m*/

    return new Writer() {
        @Override
        public void write() throws Exception {
            if (eventIterator.hasNext()) {
                T event = eventIterator.next();
                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);
            } else {
                jsonGenerator.writeEndArray();
                jsonGenerator.flush();
                out.close();
            }
        }
    };
}

From source file:de.odysseus.staxon.json.stream.jackson.JacksonStreamFactory.java

@Override
public JsonStreamTarget createJsonStreamTarget(OutputStream output, boolean pretty) throws IOException {
    return new JacksonStreamTarget(configure(jsonFactory.createGenerator(output, JsonEncoding.UTF8), pretty));
}

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

public final static void manyCompanies2JSON(HashSet<Company> companies, ByteArrayOutputStream outStream)
        throws IOException {
    JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8);
    jgenerator.writeStartObject();//  w  w w .  ja v  a2 s.c  o m
    jgenerator.writeArrayFieldStart("companies");
    Iterator<Company> iter = companies.iterator();
    while (iter.hasNext()) {
        Company current = iter.next();
        CompanyJSON.company2JSON(current, jgenerator);
    }
    jgenerator.writeEndArray();
    jgenerator.writeEndObject();
    jgenerator.close();
}

From source file:io.debezium.document.JacksonWriter.java

@Override
public byte[] writeAsBytes(Document document) {
    try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
        try (JsonGenerator jsonGenerator = factory.createGenerator(stream, JsonEncoding.UTF8)) {
            configure(jsonGenerator);/*from www .j a v  a  2 s  . co  m*/
            writeDocument(document, jsonGenerator);
        }
        return stream.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

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

public final static void manyTeams2JSON(HashSet<Team> teams, ByteArrayOutputStream outStream)
        throws IOException {
    JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8);
    jgenerator.writeStartObject();/*from   www .  ja v  a  2 s.c om*/
    jgenerator.writeArrayFieldStart("teams");
    Iterator<Team> iter = teams.iterator();
    while (iter.hasNext()) {
        Team current = iter.next();
        TeamJSON.team2JSON(current, jgenerator);
    }
    jgenerator.writeEndArray();
    jgenerator.writeEndObject();
    jgenerator.close();
}