FasterXML / FasterXML/jackson-annotations

@JsonIgnore on interface takes precedence over @JsonIgnore(false) on subclass

Offen
#306 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
1.1k
Forks
342
Ø Merge
8 Std. 53 Min.
Gemergte PRs (30 T.)
2

Beschreibung

I found that a getter annotated with `@JsonIgnore(false)` in the subclass does not override `@JsonIgnore` in the implemented interface, even though `@JsonIgnore(false)` in the subclass should logically take precedence over the interface-level ignore.

**Minimal reproduction:**
```java
public class Person extends BasicPerson implements PersonInterface{
public Person(String name) {
super(name);
}

public static void main(String[] args) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
Person demoObject = new Person("Maksym");
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

String json = objectMapper.writeValueAsString(demoObject);
System.out.println(json);
}
}

abstract class BasicPerson {
protected String name;

public BasicPerson(String name) {
this.name = name;
}

@JsonIgnore(false)
public String getName() {
return name;
}
}

interface PersonInterface {
@JsonIgnore
String getName();
}
```
Expected output:
```json
{"name":"Maksym"}
```
Current result:
```json
{}
```
Jackson version `2.19.2`

Correct me if this behavior is apparent to others, but I believe that since a Java class can have only one superclass and can implement multiple interfaces, it makes sense that configuration from the subclass should take precedence over the interface.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.