-1

Trying to override a JSON propert to return date in long format. But it does not seem to work.

@JsonIgnore
@JsonProperty("dateTime")
public long getDateTimeInLong() {
    return getDateTime().getTime(); //belongs to super class. It is an AspectJ implementation.
}

If I remove the @JsonIgnore annotation I get Conflicting getter definitions for property "dateTime": exception.

Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291

2 Answers2

3

The error message describes itself. It occurs because you have conflicting getter definitions.

You can fix it by resolving the getter conflict. I suppose you already have getDateTime() method that has the @JsonProperty annotation. You can just remove the annotation or add @JsonIgnore. Both ways should work. If the method is defined in the super class you can override the method and redefine its annotations.

Alexey Gavrilov
  • 10,593
  • 2
  • 38
  • 48
  • Did not get you on the second part. How would ignore existing `getDateTime()`? Do I need to add another `getDateTime()` and `@JsonIgnore` it? – Himanshu Yadav Jul 21 '14 at 15:43
-1

I'd avoid using annotations for data representation purposes, since it probably would pollute your code, design would become 'representation centric'. Unless you're using that object as DTO, but that's another anti pattern. Instead I'd separate representation concerns, there's already an answer how to do that.

Community
  • 1
  • 1