Fasterxml:无法从json解析子类型

时间:2013-12-18 19:35:48

标签: java json fasterxml

问题:

Fasterxml可以在setter中使用抽象时构造一个对象。见下面的代码

Can not construct instance of CarState, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information

代码:

@MappedSuperclass
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
public interface IState {}

public class BusState implements IState{}

//register subtype in mapper
mapper.registerSubtypes(BusState .class);   

public interface Car {
  public void setState(IState state); 
}

@Entity
public class Bus implements Car {

  private BusState state;

  public void getState(BusState state) { //Seems fasterxml doesn't use this method, instead it use Car.setState
    this.state = state;
  }
}

我可以在Bus课程中创建两种不同的方法:一种用于设置IState,另一种用于BusState。但它看起来很难看。

问题:

如何使quickxml正确构造Bus - 对象?

0 个答案:

没有答案