0

I'm using Jackson's JsonSchemaGenerator to generate schemas for my beans. One of these beans have a getter that I would like to exclude from the schema generation (or alternatively, mark is as an "object" - not any).

How would I go about generating a schema but forcing the address property to be either excluded or any object?

public static class Person {

    private final String firstName;

    private final String lastName;

    private final Address address;

    public Person(
            @JsonProperty("first_name") String firstName,
            @JsonProperty("last_name") String lastName,
            @JsonProperty("address") Address address) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
    }

    @JsonProperty("first_name")
    public String getFirstName() {
        return firstName;
    }

    @JsonProperty("last_name")
    public String getLastName() {
        return lastName;
    }

    @JsonProperty("address")
    public Address getAddress() {
        return address;
    }
}

I haven't found a way to achieve this using Jackson.

Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
  • 1
    I am not sure I fully understood what you want to achieve but maybe it can be accomplished with `@JsonIgnore`? – NeoChiri Jul 28 '20 at 06:32
  • What do you mean by "or any object"? – Dani Mesejo Jul 28 '20 at 06:36
  • If I did use the JsonIgnore, it would be excluded entirely from serialization. Ideally I just don't want a schema for the address field and it doesn't need to be `"address" : { "type" : "any" }` It should simply be `"address" : {}` – Mridang Agarwalla Jul 28 '20 at 07:12
  • By design, this (slightly outdated) schema generator aims at reflecting what Jackson returns. Your best options are probably manipulating the generated schema afterwards or use a different generator library (I'm biased here as maintainer of one such alternative). – Carsten Jul 28 '20 at 11:51

0 Answers0