apache / apache/grails-core

Can not find codec for org.grails.web.json.JSONObject or groovy.json.internal.LazyMap

Open
#14,409 4 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-mongodb
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

In my Grails 3.3.6 and mongo gormVersion=6.1.10.RELEASE app's controller I have a class:
```
@Entity
class Extension {
String id
Map values
}
```
where values represent a JSON tree, and an action:

```
def update() {
def json = request.JSON
Extension e = Extension.findOrCreateByName json.name
e.values = json.values // << here no codec for org.grails.web.json.JSONObject is thrown
e.values = new JsonSlurper().parseText json.values.toString() // << here no codec for groovy.json.internal.LazyMap is thrown
e.values = new ObjectMapper().readValue json.values.toString(), HashMap // only this works
e.save()
}
```

So, the respective "no codec found" exceptions are thrown during persisting in mongo.
There should be added those codecs to allow for straight use of JSONObject and JsonSlurper.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the controller action with Extension.values assigned from request.JSON and from JsonSlurper, then inspect the Mongo persistence codec handling. Compare the failing JSONObject and LazyMap cases with the working ObjectMapper-to-HashMap case. Done means both reported map types can be persisted without a no-codec exception, with regression coverage for the two assignments.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, mongodb
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.