Skip to content

Instantly share code, notes, and snippets.

@vegegoku
Created February 28, 2020 13:26
Show Gist options
  • Save vegegoku/6b7339c61f374d054f402214a167e562 to your computer and use it in GitHub Desktop.
Save vegegoku/6b7339c61f374d054f402214a167e562 to your computer and use it in GitHub Desktop.
public final class SimpleBeanBeanJsonSerializerImpl extends AbstractBeanJsonSerializer<SimpleBean> {
public SimpleBeanBeanJsonSerializerImpl() {
}
@Override
public Class getSerializedType() {
return SimpleBean.class;
}
@Override
protected BeanPropertySerializer[] initSerializers() {
BeanPropertySerializer[] result = new BeanPropertySerializer[2];
result[0] = new BeanPropertySerializer<SimpleBean, Integer>("id") {
@Override
protected JsonSerializer<?> newSerializer() {
return BaseNumberJsonSerializer.IntegerJsonSerializer.getInstance();
}
@Override
public Integer getValue(SimpleBean bean, JsonSerializationContext ctx) {
return bean.getId();
}
};
result[1] = new BeanPropertySerializer<SimpleBean, String>("name") {
@Override
protected JsonSerializer<?> newSerializer() {
return StringJsonSerializer.getInstance();
}
@Override
public String getValue(SimpleBean bean, JsonSerializationContext ctx) {
return bean.getName();
}
};
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment