Skip to content

Commit dbe8c7b

Browse files
committed
document simple enum converter
1 parent 9beb261 commit dbe8c7b

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

grails-doc/src/en/guide/upgrading/upgrading60x.adoc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,74 @@ If your application or API consumers depend on the previous JSON format for `Cal
683683
4. **ZonedDateTime**: Note that the zone ID (e.g., `[America/Los_Angeles]`) is no longer included in the output, matching Spring Boot's behavior.
684684

685685
This change applies to both the `grails-converters` module (standard JSON rendering) and the `grails-views-gson` module (JSON views).
686+
687+
===== 12.26 Enum JSON/XML Serialization
688+
689+
As of Grails 7.0.2, enum serialization has been enhanced to support round-trip compatibility between JSON/XML serialization and deserialization. The legacy enum marshaller, which produced verbose output with type metadata, has been deprecated in favor of a simpler format that matches how enums are expected on input.
690+
691+
====== Legacy Behavior (Deprecated)
692+
693+
Previously, enums were serialized with metadata:
694+
695+
*JSON:*
696+
[source,json]
697+
----
698+
{
699+
"stage": {
700+
"enumType": "com.example.ChallengeStage",
701+
"name": "SUBMIT"
702+
}
703+
}
704+
----
705+
706+
*XML:*
707+
[source,xml]
708+
----
709+
<stage enumType="com.example.ChallengeStage">SUBMIT</stage>
710+
----
711+
712+
This format is **asymmetric** - when POSTing data, you send `"stage":"SUBMIT"`, but when GETting data, you receive the verbose object structure.
713+
714+
====== New Behavior (Recommended)
715+
716+
The new `SimpleEnumMarshaller` serializes enums as simple string values, providing **round-trip compatibility**:
717+
718+
*JSON:*
719+
[source,json]
720+
----
721+
{
722+
"stage": "SUBMIT"
723+
}
724+
----
725+
726+
*XML:*
727+
[source,xml]
728+
----
729+
<stage>SUBMIT</stage>
730+
----
731+
732+
Now the format you POST is the same format you GET back.
733+
734+
====== Migration
735+
736+
To opt-in to the new behavior, add the following to your `application.yml`:
737+
738+
[source,yml]
739+
.application.yml
740+
----
741+
grails:
742+
converters:
743+
json:
744+
enum:
745+
format: simple
746+
xml:
747+
enum:
748+
format: simple
749+
----
750+
751+
====== Deprecation Timeline
752+
753+
* **7.0.2**: Legacy `EnumMarshaller` deprecated (default), `SimpleEnumMarshaller` available via config
754+
* **8.0**: `SimpleEnumMarshaller` will become the default
755+
756+
The legacy `org.grails.web.converters.marshaller.json.EnumMarshaller` and `org.grails.web.converters.marshaller.xml.EnumMarshaller` classes are marked as `@Deprecated(forRemoval = true, since = "7.0.2")` and will be removed in Grails 8.0.

0 commit comments

Comments
 (0)