Search in sources :

Example 21 with JsonGenerator

use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.

the class JsonSerializerGWT method writePerunRuntimeException.

@Override
public void writePerunRuntimeException(PerunRuntimeException prex) throws IOException {
    JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
    if (prex == null) {
        throw new IllegalArgumentException("prex is null");
    } else {
        gen.writeStartObject();
        gen.writeStringField("errorId", prex.getErrorId());
        gen.writeStringField("type", prex.getClass().getSimpleName());
        gen.writeStringField("errorInfo", prex.getMessage());
        gen.writeEndObject();
    }
    gen.close();
}
Also used : JsonGenerator(org.codehaus.jackson.JsonGenerator)

Example 22 with JsonGenerator

use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.

the class JsonSerializerGWT method writePerunException.

@Override
public void writePerunException(PerunException pex) throws IOException {
    JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
    if (pex == null) {
        throw new IllegalArgumentException("pex is null");
    } else {
        gen.writeStartObject();
        gen.writeStringField("errorId", pex.getErrorId());
        if (pex instanceof RpcException) {
            gen.writeStringField("type", ((RpcException) pex).getType());
            gen.writeStringField("errorInfo", ((RpcException) pex).getErrorInfo());
        } else {
            gen.writeStringField("type", pex.getClass().getSimpleName());
            gen.writeStringField("errorInfo", pex.getMessage());
        }
        // write reason param for this case
        if (pex instanceof ExtendMembershipException) {
            gen.writeStringField("reason", ((ExtendMembershipException) pex).getReason().toString());
        }
        gen.writeEndObject();
    }
    gen.close();
}
Also used : RpcException(cz.metacentrum.perun.core.api.exceptions.RpcException) JsonGenerator(org.codehaus.jackson.JsonGenerator) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException)

Example 23 with JsonGenerator

use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.

the class JsonSerializerJSONSIMPLE method write.

@Override
public void write(Object object) throws RpcException, IOException {
    JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
    try {
        gen.writeObject(object);
        gen.flush();
        gen.close();
    } catch (JsonProcessingException ex) {
        throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
    }
}
Also used : RpcException(cz.metacentrum.perun.core.api.exceptions.RpcException) JsonGenerator(org.codehaus.jackson.JsonGenerator) JsonProcessingException(org.codehaus.jackson.JsonProcessingException)

Example 24 with JsonGenerator

use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.

the class JsonSerializer method writePerunException.

@Override
public void writePerunException(PerunException pex) throws IOException {
    JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
    if (pex == null) {
        throw new IllegalArgumentException("pex is null");
    } else {
        gen.writeObject(pex);
        gen.flush();
    }
    gen.close();
}
Also used : JsonGenerator(org.codehaus.jackson.JsonGenerator)

Example 25 with JsonGenerator

use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.

the class JsonSerializer method write.

@Override
public void write(Object object) throws RpcException, IOException {
    JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
    try {
        gen.writeObject(object);
        gen.flush();
        gen.close();
    } catch (JsonProcessingException ex) {
        throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
    }
}
Also used : RpcException(cz.metacentrum.perun.core.api.exceptions.RpcException) JsonGenerator(org.codehaus.jackson.JsonGenerator) JsonProcessingException(org.codehaus.jackson.JsonProcessingException)

Aggregations

JsonGenerator (org.codehaus.jackson.JsonGenerator)54 JsonFactory (org.codehaus.jackson.JsonFactory)15 IOException (java.io.IOException)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)11 StringWriter (java.io.StringWriter)10 JsonProcessingException (org.codehaus.jackson.JsonProcessingException)8 RpcException (cz.metacentrum.perun.core.api.exceptions.RpcException)6 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)5 JsonNode (org.codehaus.jackson.JsonNode)5 OutputStreamWriter (java.io.OutputStreamWriter)4 HashMap (java.util.HashMap)4 File (java.io.File)3 PrintWriter (java.io.PrintWriter)3 GET (javax.ws.rs.GET)3 Response (javax.ws.rs.core.Response)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 BufferedWriter (java.io.BufferedWriter)2 DataOutputStream (java.io.DataOutputStream)2 ArrayList (java.util.ArrayList)2