From b5f5a4048d1c594792591dce8028751ba0e7c058 Mon Sep 17 00:00:00 2001 From: SangHyun-Park <51109514+PPakSang@users.noreply.github.com> Date: Sat, 19 Mar 2022 15:56:49 +0900 Subject: [PATCH] Update MyJsonComponent.java If you follow the docs writing custom json serializer, it throws an exception "JsonGenerationException". Of course, if there is an existing Json Generator, it is applicable code, but users (including myself) who usually follow docs are more likely to write the code first. Therefore, I think that the text should be modified as an example with the addition of JsonGenerator.writeStartObject()/writeEndObject() or a separate notice should exist for that part. --- .../boot/docs/web/servlet/springmvc/json/MyJsonComponent.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.java index ad2c98dfd909..23b35fd0a05a 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.java @@ -36,8 +36,10 @@ public static class Serializer extends JsonSerializer { @Override public void serialize(MyObject value, JsonGenerator jgen, SerializerProvider serializers) throws IOException { + jgen.writeStartObject(); jgen.writeStringField("name", value.getName()); jgen.writeNumberField("age", value.getAge()); + jgen.writeEndObject(); } }