Restful jboss 反序列化

Restful jboss Deserialize

我正在 JBoss AS 7.1.1 Final 中构建一个 restful 网络服务。它工作得很好,直到我需要一个自定义反序列化器。代码:

@Entity
@DiscriminatorColumn(name = "tipo")
@Table(name = "debitavel", schema = "despesas_db")
@Inheritance(strategy = InheritanceType.JOINED)
@JsonDeserialize(using = DebitavelDeserializer.class)
@JsonSerialize(using = DebitavelSerializer.class)
public abstract class Debitavel {

}

这个class有2个子class:

@Entity
@Table(name = "conta", schema = "despesas_db")
@DiscriminatorValue(value = "CONTA")
public class Conta extends Debitavel {
}

@Entity
@DiscriminatorValue(value = "CONTA")
@Table(name = "cartao", schema = "despesas_db")
public class CartaoCredito extends Debitavel {
}

我有这个 class 使用 Debitvel:

@Entity
@Table(name = "despesa", schema = "despesas_db")
@DiscriminatorValue(value = "D")
public class Despesa {

    @Column
    private String descricao;

    @ManyToOne
    @JoinColumn(name = "debitavel_id")
    protected Debitavel debitavel;

}

所以在页面中我发送了一个 json 这样的

{
    "descricao": "TESTE",
    "debitavel": {
         "id": 101,
         "descricao": "Conta1",
         "cor": "#ff0000",
         "tipo": "CONTA"
    }
}

所以,我想要一个 class 来创建一个基于属性类型的 CartaoCredito 或 Conta 实例,所以我构建了一个反序列化器:

public class DebitavelDeserializer extends JsonDeserializer<Debitavel> {

      @Override
      public Debitavel deserialize(JsonParser jp, DeserializationContext ctxt)     throws IOException, JsonProcessingException {
              //staff to create Conta or CartaoCredito
      }

}

还有我的pom.xml:

         <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.12</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.12</version>
        </dependency>

但是,当我尝试部署应用程序时,jboss 说 Debitavel 是一个抽象的 class,它无法构建实例。我寻找解决方案并尝试了几种解决方案:

它看到 jboss 简单地忽略了那些注释。

谢谢

我解决了...但是说实话我不明白为什么,让我们看看:

我将 pom.xml 更改为

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>2.3.2.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
            <version>2.3.2.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson-provider</artifactId>
            <version>2.3.2.Final</version>
        </dependency>

一切正常。有人可以解释为什么这样做吗?