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

Generated attribute takes first type on types list. #1425

Closed
Jummartinezro opened this issue Aug 5, 2022 · 4 comments · Fixed by #1456
Closed

Generated attribute takes first type on types list. #1425

Jummartinezro opened this issue Aug 5, 2022 · 4 comments · Fixed by #1456

Comments

@Jummartinezro
Copy link

Consider the following jsonSchema:

  {
        "type" : "object",
        "properties" : {
            "foo" : {
                "type" : ["boolean", "string","number","integer"]
            }
        }
    }

In this case generated attribute foo will have as type Boolean:

package com.example;

import javax.annotation.Generated;

@Generated("jsonschema2pojo")
public class Example {

public Boolean foo;

}

I noticed that, if type is not specified in jsonSchema, foo takes the type Object:

  {
        "type" : "object",
        "properties" : {
            "foo" : {
            }
        }
    }

Result:

package com.example;

import javax.annotation.Generated;

@Generated("jsonschema2pojo")
public class Example {

public Object foo;

}

There's a way of having the last result (without changing the jsonSchema) when a list of types is passed ?

@Jummartinezro
Copy link
Author

Maybe related to #676 ?

@eirnym
Copy link

eirnym commented Aug 5, 2022

Yes, it's directly related and the answer will be the same

@joelittlejohn
Copy link
Owner

Often people use union types like: ["boolean", null], where the result is an optional value. In this case, it's obviously desirable to just take the first item. It would probably be better if use we use the following logic for union types:

  1. Remove null values.
  2. If one value remains, use this as the type; If multiple values remain, use Object as the type.

@eirnym
Copy link

eirnym commented Aug 7, 2022

Logic of taking first type should be changed, as a user can pass ["null", "boolean"] and should have the same result

unkish added a commit to unkish/jsonschema2pojo that referenced this issue Dec 21, 2022
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Dec 21, 2022
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Jan 6, 2023
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Jan 8, 2023
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Jan 8, 2023
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Jan 23, 2023
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Jan 26, 2023
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Feb 5, 2023
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Feb 7, 2023
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants