Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring@JsonSubTypes具有非常不同的抽象类结构_Java_Json_Spring_Jackson - Fatal编程技术网

Java Spring@JsonSubTypes具有非常不同的抽象类结构

Java Spring@JsonSubTypes具有非常不同的抽象类结构,java,json,spring,jackson,Java,Json,Spring,Jackson,我正在尝试从HTTP请求接收时间对象。以下请求是可能的,每个请求都应生成不同的类 time: { type: relative | absolute, value: string(eg:L24H) | {startTime: xxxx, endTime: xxxx} } 基于类型生成的类。希望这一部分是不言自明的。 我用一个摘要制作了下面的结构,并用两个类来扩展它 @JsonTypeInfo( use =Id.NAME, include =

我正在尝试从HTTP请求接收时间对象。以下请求是可能的,每个请求都应生成不同的类

time: {
    type: relative          | absolute,
    value: string(eg:L24H)  | {startTime: xxxx, endTime: xxxx}
}
基于
类型生成的类
。希望这一部分是不言自明的。 我用一个摘要制作了下面的结构,并用两个类来扩展它

@JsonTypeInfo(
    use =Id.NAME,
    include = As.PROPERTY,
    property = "type",
    visible = true
)
@JsonSubTypes({

    @JsonSubTypes.Type(value = RelativeSearchTimeRange.class, name = "relative"),
    @JsonSubTypes.Type(value = AbsoluteSearchTimeRange.class, name = "absolute")


})

public abstract class SearchTimeRange<V> {
  private String type;

  private V value;

  private Time time;

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }


  public V getValue() {
    return value;
  }

  public void setValue(V value) {
      this.value = value;
    }
}

AbsoluteTimeRange
中我缺少了什么?

我仍然不确定它为什么会起作用,但我必须向
AbsoluteTimeRange
类添加一个默认构造函数

如果有人能进一步澄清,我们将非常欢迎

public class RelativeSearchTimeRange extends SearchTimeRange<RelativeSearchTimeRange.RelativeTime> {

  enum RelativeTime {
    L24H, L3D;
  }

  private RelativeTime value;


  @Override public void setValue(RelativeTime value) {
    this.value = value;
  }

  @Override public RelativeTime getValue() {
    return value;
  }
public class AbsoluteSearchTimeRange extends SearchTimeRange<AbsoluteSearchTimeRange> {

  private Time value;

public void setValue(Time value) {
    this.value = value;
  }

  public AbsoluteSearchTimeRange(Long startTime, Long endTime) {
    value = new Time(startTime, endTime);
  }

  @Override public Time getTime() {
    return value;
  }
}
public class Time {
  long startTime;
  long endTime;
}