-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#617]User defined deserializer always should be used before standard… #619
base: master
Are you sure you want to change the base?
Conversation
…ore standard ones
It is working fine right now, but it also could be tested. Signed-off-by: Anton Pinsky <[email protected]>
…nnotation on enum constants Signed-off-by: Anton Pinsky <[email protected]>
On commit for #616. I've changed both EnumSerializer and EnumDeserializer, of course. Now they build the map in the constructor, and use it. The map is filled according to the PropertyModel#getxxxName. So the annotation value has effect. In EnumDeserializer I needed a whole jsonbContext to get the models. Because of this, I've changed the TypeDeserializerBuilder to set and get the JsonbContext as parameter. There is still a getter for JsonbConfigProperties, but we can remove it. If we do this, we have to change another three classes which use this getter. |
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Hello, thank you for your contribution! Would it be possible to ask to to update also the class copyright years? :-) |
As far as I can tell, some of the copyright failures are caused by my mistake some time ago and will fix them. As of the rest, I might kindly ask you to fix them.
These are the ones I will create PR for tomorrow. |
Signed-off-by: Anton Pinsky <[email protected]>
Copyright - done, even if it wasn't mine! ;-) |
Alright, I fixed the master and everything should be correct now! :-) It sill look like there might be some copyright years remaining to fix. |
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
The other possible change was to move the creation of EnumDeserializer out of the TypeDeserializers chain, direct into the DeserializationModelCreator. Then I wouldn't have to change the TypeDeserializerBuilder. But this looks like a more destructive change for me. Of course, it also could be done. |
Signed-off-by: Anton Pinsky <[email protected]>
This reverts commit c92319f.
Signed-off-by: Anton Pinsky <[email protected]>
…into try-with-resources. Signed-off-by: Anton Pinsky <[email protected]>
Put every call of JsonbBuilder.create in the tests into try-with-resources. There is a discussion about similar things here #586. I don't know if this should be done or not right now. Anyway, I just did it. It is only in the test code, so there we could close any resource of the created JSON instance and builder. If there is an exception during auto-closing - I think it should break a test. But it also could be irrelevant for the test, so we could silently catch the exception. This also could be discussed. |
Signed-off-by: Anton Pinsky <[email protected]>
…oved Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
…e Java 16 Signed-off-by: Anton Pinsky <[email protected]>
…t configuration is used Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
…arning during the compilation Signed-off-by: Anton Pinsky <[email protected]>
…rown here), so there would be less of "auto-close" warnings Signed-off-by: Anton Pinsky <[email protected]>
…r warnings from module system Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
…gs about modules Signed-off-by: Anton Pinsky <[email protected]>
…y are required on the client to run this Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
…he YassonParser's skipXXX and streamXXX methods Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
… etc. implementation; YassonParser & JsonStructureToParserAdapter fulfill more JSONP JsonParser Signed-off-by: Anton Pinsky <[email protected]>
…\_(ツ)_/¯ Signed-off-by: Anton Pinsky <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing changes to Yasson :-)
I have a few things to note here:
- since this will be very likely get merged some time after the New Year, It will need to have updated copyright years for a changed files to 2024.
- If possible, please list here all the issues it fixes
- I am usually squashing everything when merging, to do not have 100 new commits, but rather one. Are you fine with that?
<!-- execution> | ||
<id>add-source</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>add-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>${project.basedir}/src/main/java16</source> | ||
</sources> | ||
</configuration> | ||
</execution --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be removed, if it is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I addressed your approach of making the multi-release JAR, for java pre-16 and above. So the Java 16 sources are now included by plugin and not by manipulation of the compiler plugin configuration. This worked only for test classes but not for main classes; therefore I commended this part out.
The question is: would we like to get the multi-release somehow through some official / right way (there are some now)? Or should we forget it?
I don't think that you got multi-release JAR before, just the compilation and creation of the different JARs for different versions. So maybe this multi-release wasn't a goal anyway? And shouldn't be reached?
As about this comment - I can remove it independently of the decision about the above topic.
public JsonBindingProvider() { | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not needed, since it is added by compile by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I wrote in commit comment this is because of JPMS: these are the classes in the root package, which is exported. So I get warnings from the compiler, which suggests adding an explicit constructor. I think the public one is OK, because we should be able to create the instances of these classes outside the packages?
|
||
public YassonConfig() { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not needed, since it is added by compile by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
src/main/java/org/eclipse/yasson/internal/AnnotationIntrospector.java
Outdated
Show resolved
Hide resolved
final Class<? extends JsonbAdapter> adapterClass = adapterAnnotation.value(); | ||
final AdapterBinding adapterBinding = jsonbContext.getComponentMatcher().introspectAdapterBinding(adapterClass, null); | ||
@SuppressWarnings("unchecked") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... I think this annotation might be better placed on the Method level. (I will not mark it in other cases I see this.)
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with suppression on the method level - you suppress all such things everywhere in the method. So if you put a new one, which you probably wouldn't like to be suppressed and paid attention to it - it also would be automatically suppressed in such case. So I try to put the thing like this directly at the point where it happens, so no other occurrences would be suppressed.
Sometimes I have to change code a little because of this. For example, in case of something would be cast without check directly at return of the method, but one can't put suppress on the return. So I have to extract the result of the cast into the new variable, where I can suppress the unchecked cast warning; and return this variable in the next line.
I think this is a healthy approach.
constantToNameMap.put(enumConstant, model.getWriteName()); | ||
} | ||
} catch (ClassCastException classCastException) { | ||
throw new IllegalArgumentException("EnumSerializer can only be used with Enum types"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never happen, if method isEnum is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CCE could happen here not because I cast the class to the enum class, but to some definite enum class E in line 43. Otherwise, I wouldn't have typed constants in the loop. If you think that this wouldn't happen or cause the exception - I can remove the try-catch block. Or if you think that it's OK to have here a CCE been thrown and not IAE.
} | ||
|
||
@Override | ||
void serializeValue(Enum<?> value, JsonGenerator generator, SerializationContextImpl context) { | ||
generator.write(value.name()); | ||
generator.write(constantToNameMap == null ? value.name() : constantToNameMap.get(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same as wit Deserializer. When this map can be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already answered this above in deserializer.
@@ -22,4 +25,32 @@ public class Jsonbs { | |||
public static final Jsonb nullableJsonb = JsonbBuilder.create(new JsonbConfig().withNullValues(Boolean.TRUE)); | |||
public static final YassonJsonb yassonJsonb = (YassonJsonb) JsonbBuilder.create(); | |||
public static final YassonJsonb bindingYassonJsonb = (YassonJsonb) new JsonBindingProvider().create().build(); | |||
|
|||
private static void testWithJsonb(Supplier<Jsonb> supplier, Consumer<Jsonb> consumer){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you decided to create these methods? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the tests, one always need a Jsonb object to test it. So there are these repeating parts in the test which creates this object one way or another. Sometimes it is in the try-with-resources block, sometimes one forgot about this.
So I extracted these repeating parts into the methods. These methods are the fixtures for the test. The test gets the Jsonb over the consumer and only have to implement the test logic itself in the consumer. No need to write this boilerplate code over and over again, with some unneeded combinations.
I choose to place these methods into this class because this class already has some common constants and methods which used all over the test code. If you think we need another class just for these static methods - I can do it.
src/test/java/org/eclipse/yasson/adapters/model/NumberAdapter.java
Outdated
Show resolved
Hide resolved
@@ -87,6 +85,7 @@ public void testNillableInConfig() { | |||
|
|||
public static class PrimitiveNullBoolean { | |||
|
|||
@SuppressWarnings("deprecation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly does this mean on the field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using the deprecated parameter (nillable) on the annotation (@JsonbProperty) here. Therefore, I have a suppressor on the field. I think this is an old test from the times when this parameter wasn't deprecated. So suppression is ok right now; this test would be removed as soon as the parameter would be also removed and wouldn't be just deprecated.
…plugins update in POM; assertInstanceOf where this is possible Signed-off-by: Anton Pinsky <[email protected]>
…tor & DeserializationModelCreator in serializer / deserializer creation from serializer / deserializer / adapter configuration in annotations Signed-off-by: Anton Pinsky <[email protected]>
…tor & DeserializationModelCreator in serializer / deserializer creation from serializer / deserializer / adapter configuration in annotations Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
Signed-off-by: Anton Pinsky <[email protected]>
…ctionUtils Signed-off-by: Anton Pinsky <[email protected]>
…r and Adapter in tests Signed-off-by: Anton Pinsky <[email protected]>
Besides, after fixing the main issue, I've done some refactoring and warning fixing. If you need this, I can add some rough description of them, building some groups. At maximum, I can just assemble the list of all comments in my pushes in this PR, except for some small corrections and forgotten classes. Just tell me how deep and long this list should be
|
Signed-off-by: Anton Pinsky <[email protected]>
…or and DeserializationModelCreator; fixed bug in ReflectionUtils Signed-off-by: Anton Pinsky <[email protected]>
I found a missing case in ReflectionUtils#getOptionalRawType (WildcardType). I closed this and wrote the test. Furthermore, I don't think that we need an extra ticket for this bug - there was an exception in this case. |
… ones.
Created a correction for #617. I little bit of explanations: the culprit is in the TypeDeserializers#assignableCases. Here, the EnumDeserializer will be created for any Enum type. But here we are missing some objects needed to create a user deserializer. So we have to create it earlier in the call stack, directly in the DeserializationModelCreator#deserializerChainInternal, before the call of DeserializationModelCreator#typeDeserializer.
This way it would be effective for all classes, not just the enums.
On the other hand, I looked on the SerializationModelCreator. Here one first looks in the cache, then for user defined serializer, then for user defined adapter. And only after that the standard serializer would be created. So now both DeserializationModelCreator and SerializationModelCreator will share the same logic on creation of custom / standard elements.
And I forget an
Signed-off-by: Anton Pinsky <[email protected]>
- could I change it?