Romain Manni-Bucau commented on JOHNZON-307:

Hi [~BenoitP],


The rational was that generally .*$.* fields are synthetic or generated fields 
the mapper shouldn't take into account. However it does not mean you can't use 
a $name field, it is just a constraint on the field/method name, not on the 
JSON name.

Typically, for OpenAPI, [Geronimo 
OpenAPI|[https://github.com/apache/geronimo-openapi]] (which implements v3) 
private String ref; {code}
In other words, a simple solution is to add a getter/setter to the model class 
without the $ and forward the value access/write to the $ field.

> POJO's field or method name containing the $ character is not serialized
> ------------------------------------------------------------------------
>                 Key: JOHNZON-307
>                 URL: https://issues.apache.org/jira/browse/JOHNZON-307
>             Project: Johnzon
>          Issue Type: Bug
>          Components: Mapper
>    Affects Versions: 1.1.12, 1.2.3
>            Reporter: Benoit Prudhomme
>            Priority: Major
>             Fix For: 1.2.4
> We are building an _Open API 3.0_ generator based on 
> _io.swagger.core.v3:swagger-models:2.1.1_. The features coming from the 
> version 3.0 are *mandatory* for us, specially the ability to make references.
> However references use the _*$ref*_ ([Structuring a complex JSON 
> schema|https://json-schema.org/understanding-json-schema/structuring.html]) 
> keyword in the JSON key.
> example:
> {code:java}
> "schema": {
>  "$ref": "#/components/schemas/user" 
> }{code}
> Since the commit bcf51d2e5b1267dcf317816b7db759460cb3c715 ([more global 
> exclude rules for fields and 
> methods|https://github.com/apache/johnzon/commit/bcf51d2e5b1267dcf317816b7db759460cb3c715]),
>  every field or method name containing the _*$*_ is ignore and not serialized.
> Currently, we extended the classes:
> _com.onwbp.org.apache.johnzon.mapper.access.FieldAccessMode_
> _com.onwbp.org.apache.johnzon.mapper.access.MethodAccessMode_
> to override this behavior. 
> Unfortunatly, the class 
> _com.onwbp.org.apache.johnzon.mapper.access.FieldAndMethodAccessMode_ and 
> every classes making direct references to them have to be forked to use our 
> extensions.
> Since the _*isIgnored*_ method is _*protected*_ we though that the behavior 
> could be easily overriden.
> *Can the ignore filter be fixed to allow, at least, the _$ref_ keyword ?* 
> *In absence of fix, can you provide us the best way to override the ignore 
> filter algorithm ?*
> Note: since _*$id*_ and _*$schema*_ are specified as well in the JSON Schema, 
> they should not be filtered when present in POJO's field or method name.

This message was sent by Atlassian Jira

Reply via email to