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

additionalProperties not correctly handled #1662

Open
bradzacher opened this issue Jan 14, 2025 · 0 comments
Open

additionalProperties not correctly handled #1662

bradzacher opened this issue Jan 14, 2025 · 0 comments

Comments

@bradzacher
Copy link

bradzacher commented Jan 14, 2025

I'm trying to generate types for the SARIF JSON Schema spec - https://json.schemastore.org/sarif-2.1.0.json

In particular they have defined:

{
  "originalUriBaseIds": {
    "description": "The artifact location specified by each uriBaseId symbol on the machine where the tool originally ran.",
    "type": "object",
    "additionalProperties": {
      "$ref": "#/definitions/artifactLocation"
    }
  },
}

I would have expected that this would generate a class with additionalProperties as mentioned in the wiki, like:

public class OriginalUriBaseIds {
  private java.util.Map<String, ArtifactLocation> additionalProperties = new java.util.HashMap<String, ArtifactLocation>();
  
  // ...
}

However instead this generates a class without additionalProperties:

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonPropertyOrder({

})
public class OriginalUriBaseIds {


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(OriginalUriBaseIds.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
        if (sb.charAt((sb.length()- 1)) == ',') {
            sb.setCharAt((sb.length()- 1), ']');
        } else {
            sb.append(']');
        }
        return sb.toString();
    }

    @Override
    public int hashCode() {
        int result = 1;
        return result;
    }

    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }
        if ((other instanceof OriginalUriBaseIds) == false) {
            return false;
        }
        OriginalUriBaseIds rhs = ((OriginalUriBaseIds) other);
        return true;
    }

}

This of course causes a crash when deserialising an object that uses the map

Is this a bug in the codegen, or am I "holding it wrong"?

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

No branches or pull requests

1 participant