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();
}
Aggregations