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

Java Jackson_Preset does not work for serialization and deserialization #983

Closed
dwlabcube opened this issue Nov 2, 2022 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@dwlabcube
Copy link

dwlabcube commented Nov 2, 2022

Describe the bug

Because the @builder and @Jacksonized Annotation do not take into account the Annoation-Property on the getter Method things will fail in deserialization of the object.

How to Reproduce

Generated Code of a Model "TestDevice" with one Property called nameBAG.

      codeBAG:
          type: string
  @SpringBootTest
  public class JsonTest {
      @Autowired
      private ObjectMapper objectMapper;
  
  
      @SneakyThrows
      @Test
      public void serializatinDeserializationTest() {
          TestDevice d = TestDevice.builder().codeBag("Code123").build();
          String string = objectMapper.writeValueAsString(d);
          TestDevice newD = objectMapper.readValue(string, TestDevice.class);
  
          Assertions.assertThat(string).isEqualTo("{\"codeBAG\":\"Code123\"}"); //this works
          Assertions.assertThat(newD.getcodeBag()).isEqualTo(d.getcodeBag()); //this fails
      }
  
  
      @Builder
      @Jacksonized
      public static class TestDevice {
  
          //   @JsonProperty("codeBAG") should be put here
          private String codeBag;
  
          @JsonProperty("codeBAG")
          public String getcodeBag() {
              return this.codeBag;
          }
          public void setCodeBag(String codeBag) {
              this.codeBag = codeBag;
          }
      }
  }

this Test fails with:

org.opentest4j.AssertionFailedError:
expected: "Code123"
but was: null
Expected :"Code123"
Actual :null

Expected behavior

If you put the annotation upon the Java-Field (property) things work fine.

@dwlabcube dwlabcube added the bug Something isn't working label Nov 2, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2022

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@jonaslagoni
Copy link
Member

Thanks for raising the issue @dwlabcube, are you using the next version for generating the data models?

@dwlabcube
Copy link
Author

dwlabcube commented Nov 9, 2022

no i am using
"dependencies": {
"@asyncapi/modelina": "^0.59.4",

but also with 1.0.0-next-25 same issue exists

@artur-ciocanu
Copy link
Collaborator

@dwlabcube could you please try the latest next version. It has the Jackson fix. Thank you.

@jonaslagoni
Copy link
Member

jonaslagoni commented Jan 30, 2023

Closing as this should be solved in the new version. If not feel free to re-open the issue again!

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

No branches or pull requests

3 participants