Skip to content
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

NPE in ExampleJsonGenerator with "oneof" #332

Closed
EnBW-mobility opened this issue Aug 22, 2023 · 3 comments
Closed

NPE in ExampleJsonGenerator with "oneof" #332

EnBW-mobility opened this issue Aug 22, 2023 · 3 comments
Labels
bug Something isn't working staged for release

Comments

@EnBW-mobility
Copy link

Describe the bug
I have a model where one field has a oneOf Schema annotation.
I created an interface to handle this.
As there are no properties in the schema object (only oneOf "references"), ExampleJsonGenerator throws a NPE.
Happens with "anyOf" too. Didn't check, but I guess it will crash with "allOf" too.

I saw the other bug reports regarding the NPE in this class, but I'm not sure that the cases I mentioned are covered in the fixed version.

As a workaround, I activated the old behavior as written in the release doc.
I still get errors, but at least the application is starting and I can see example data.

Dependencies and versions used
springwolf-amqp version 0.13.0.

Code example

public class Data {
  private OneOf oneOfData;
}

@Schema(oneOf = {
  ImplementationOne.class,
  ImplementationTwo.class
})
public interface OneOf {
}

public class ImplementationOne {
  private String firstOne;
  private String secondOne;
}

public class ImplementationTwo{
  private Integer firstTwo;
  private Boolean secondTwo;
}

Stack trace and error logs

Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Map.entrySet()" because "properties" is null
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.handleObject(ExampleJsonGenerator.java:134)
@EnBW-mobility EnBW-mobility added the bug Something isn't working label Aug 22, 2023
@github-actions
Copy link

Welcome to Springwolf. Thanks a lot for reporting your first issue. Please check out our contributors guide and feel free to join us on discord.

@timonback
Copy link
Member

Thank you @EnBW-mobility for the feedback.

The NPE should be fixed as part of latest -SNAPSHOT builds.

We will add the oneOf Schema property to your JsonExampleGenerator as part of #326
Thank you for this code example, it helps a lot!

To support allOf we probably need to build the json via a library instead of by hand, which will make things simplier. Right now, also for allOf only the first schema is used.

You mention that you get other errors as well. Feel free to report them as well.

@timonback
Copy link
Member

Thank your for the report, the issue has been addressed in the new release - at least the oneof case. allOf still needs improvements.

Feel free to reopen this issue if there is still something missing.

Also, please participate in #342 if you can :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working staged for release
Projects
None yet
Development

No branches or pull requests

2 participants