Commit fa541d97 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

mesh serializer implemented

parent 421436f4
......@@ -9,6 +9,10 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.annotation.data.serializer.MeSHSerializer;
/**
* This class represents <a href="http://www.nlm.nih.gov/cgi/mesh//">MeSH</a>
* object.
......@@ -17,6 +21,7 @@ import org.apache.logging.log4j.Logger;
*
*/
@XmlRootElement
@JsonSerialize(using = MeSHSerializer.class)
public class MeSH implements Serializable {
/**
......
package lcsb.mapviewer.annotation.data.serializer;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.annotation.data.MeSH;
public class MeSHSerializer extends JsonSerializer<MeSH> {
@Override
public void serialize(final MeSH mesh, final JsonGenerator gen, final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("name", mesh.getName());
gen.writeStringField("id", mesh.getMeSHId());
gen.writeStringField("description", mesh.getDescription());
gen.writeObjectField("synonyms", mesh.getSynonyms());
gen.writeEndObject();
}
}
\ No newline at end of file
......@@ -37,18 +37,13 @@ public class MeshController extends BaseController {
}
@GetMapping(value = "/{id:.+}")
public Map<String, Object> getMesh(@PathVariable(value = "id") String id)
public MeSH getMesh(@PathVariable(value = "id") String id)
throws AnnotatorException, ObjectNotFoundException {
MeSH mesh = meshService.getMesh(new MiriamData(MiriamType.MESH_2012, id));
if (mesh == null) {
throw new ObjectNotFoundException("Object not found: " + id);
}
Map<String, Object> result = new TreeMap<>();
result.put("name", mesh.getName());
result.put("id", mesh.getMeSHId());
result.put("description", mesh.getDescription());
result.put("synonyms", mesh.getSynonyms());
return result;
return mesh;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment