Search in sources :

Example 1 with JsonRootName

use of com.fasterxml.jackson.annotation.JsonRootName in project onebusaway-application-modules by camsys.

the class BodySerializer method serialize.

@Override
public void serialize(Body<T> value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
    List<T> response = value.getResponse();
    List<BodyError> errors = value.getErrors();
    String copyright = value.getCopyright();
    LastTime lastTime = value.getLastTime();
    gen.writeStartObject();
    // Copyright
    if (StringUtils.isNotBlank(copyright))
        gen.writeStringField("copyright", copyright);
    // Error
    if (errors != null && errors.size() > 0) {
        for (BodyError error : errors) error.setContent(error.getContent().replace("\\", ""));
        gen.writeObjectField("Error", errors);
    }
    // Response
    if (response != null && response.size() > 0) {
        JsonRootName jsonRootName = response.get(0).getClass().getAnnotation(JsonRootName.class);
        if (jsonRootName != null)
            gen.writeObjectField(jsonRootName.value(), response);
        else
            gen.writeObjectField("response", response);
    }
    // LastTime
    if (lastTime != null)
        gen.writeObjectField("lastTime", lastTime);
    gen.writeEndObject();
}
Also used : BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) LastTime(org.onebusaway.nextbus.model.nextbus.LastTime) JsonRootName(com.fasterxml.jackson.annotation.JsonRootName)

Aggregations

JsonRootName (com.fasterxml.jackson.annotation.JsonRootName)1 BodyError (org.onebusaway.nextbus.model.nextbus.BodyError)1 LastTime (org.onebusaway.nextbus.model.nextbus.LastTime)1