Browse Source

Implement custom JSON serializer for book category

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.2-alpha
Pekka Helenius 4 years ago
parent
commit
9abb6ff1f0
1 changed files with 30 additions and 0 deletions
  1. +30
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java

+ 30
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java View File

@ -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<Category> {
private static final long serialVersionUID = 6376700470881235634L;
public CategoryJsonSerializer() {
this(null);
}
public CategoryJsonSerializer(Class<Category> 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();
}
}

Loading…
Cancel
Save