diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java new file mode 100644 index 0000000..7b44f61 --- /dev/null +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java @@ -0,0 +1,30 @@ +package com.fjordtek.bookstore.model; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +public class CategoryJsonSerializer extends StdSerializer { + private static final long serialVersionUID = 6376700470881235634L; + + public CategoryJsonSerializer() { + this(null); + } + + public CategoryJsonSerializer(Class jd) { + super(jd); + } + + @Override + public void serialize(Category category, JsonGenerator gen, SerializerProvider provider) + throws IOException { + gen.writeStartObject(); + // Category class Id has JsonIgnore annotation + //gen.writeFieldId(category.getId()); + gen.writeStringField("name", category.getName()); + gen.writeEndObject(); + } + +} \ No newline at end of file