1

在创建新模型集群时,我遇到了 EXT-JS 和 Jackson 的问题。

这会产生以下问题:

错误 fr.package.extjs.web.controller.AbstractSpringController - inscriptionDetail.validerInscription org.springframework.http.converter.HttpMessageNotReadableException 上的错误:无法读取 JSON:无法解析对象 ID [-42](对于 [简单类型,类 fr .package.inoe.inscription.vo.InscriptionJourneeTypeVO]) -- 未解决的前向引用?(通过引用链:fr.package.inoe.inscription.vo.InscriptionDetailVO["listeSemainesType"]->fr.package.app.inscription.vo.InscriptionSemaineTypeVO["listeJourneesType"]->fr.package.app.inscription.vo .InscriptionJourneeTypeVO["listeCreneauxType"]->fr.package.app.inscription.vo.InscriptionCreneauTypeVO["journeeType"]); 嵌套异常是 com.fasterxml.jackson.databind.JsonMappingException:无法解析对象 ID [-42](对于 [简单类型,类 fr.package.app.inscription.vo.InscriptionJourneeTypeVO])——未解析的前向引用?(通过引用链:fr.package.app.inscription.vo.InscriptionDetailVO["listeSemainesType"]->fr.package.app.inscription.vo.InscriptionSemaineTypeVO["listeJourneesType"]->fr.package.app.inscription.vo .InscriptionJourneeTypeVO["listeCreneauxType"]->fr.package.app.inscription.vo.InscriptionCreneauTypeVO["journeeType"]) 在 fr.package.extjs.utils.JSONUtils.fromJsonString(JSONUtils.java:44)


以下是我的模型在 java 中的注释方式:

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class InscriptionSemaineTypeVO extends InoeVO<SemaineType, Long> implements java.lang.Comparable<InscriptionSemaineTypeVO> {

private static final long serialVersionUID = 1L;

public Long id;
private int version;
private int tri;

//   @JsonBackReference("Inscription-listeSemainesType")
private InscriptionDetailVO inscription;

//  @JsonManagedReference("InscriptionSemaineTypeVO-listeJourneesType")
private List<InscriptionJourneeTypeVO> listeJourneesType;

private long arrondiInMilli;

[...]

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class InscriptionJourneeTypeVO extends InoeVO<JourneeType, Long> implements java.lang.Comparable<InscriptionJourneeTypeVO> {

private static final long serialVersionUID = 1L;

// -------------------------------------------------------------- Attributs.

public Long id;
private int version;
private int numero;
private boolean repas;
private Time arrondi;

//  @JsonBackReference("InscriptionSemaineTypeVO-listeJourneesType")
private InscriptionSemaineTypeVO semaineType;

//  @JsonManagedReference("InscriptionJourneeTypeVO-listeCreneauxType")
private List<InscriptionCreneauTypeVO> listeCreneauxType;

[...]

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class InscriptionCreneauTypeVO extends InoeVO<CreneauType, Long> {
private static final long serialVersionUID = 1L;


public Long id;
private int version;
private Time arrivee;
private Time depart;
private Time arrondi;

//  @JsonBackReference("InscriptionJourneeTypeVO-listeCreneauxType")
private InscriptionJourneeTypeVO journeeType;

[...]

这是我的 EXTJS 模型:


Ext.define('AM.model.inscription.InscriptionSemaineTypeVO', {
extend: 'Ext.data.Model',
fields: [
            {name: 'id',      type: 'int'},
            {name: 'version',      type: 'string'},
            {name: 'tri',      type: 'string'},
            {name: 'inscription',      type: 'int'},
            {name: 'listeJourneesType'},
            {name: 'arrondiInMilli',      type: 'string'},
            {name: 'persistantClass',      type: 'string'}
        ],
        associations: 
        [
            {
                type : 'hasMany',
                name: 'listeJourneesType',
                model: 'AM.model.inscription.JourneeType'
            },
        ]

});


Ext.define('AM.model.inscription.JourneeType', {
extend: 'Ext.data.Model',
fields: [
            {name: 'numero',      type: 'string'},
            {name: 'repas',      type: 'string'},
            {name: 'arrondi',      type: 'string'},
            {name: 'semaineType'},
            {name: 'listeCreneauxType'},
            {name: 'id',      type: 'int'},
            {name: 'version',      type: 'int'}
    ],
    associations: 
    [
        {
            type : 'hasMany',
            name: 'listeCreneauxType',
            model: 'AM.model.inscription.CreneauType'
        },
        {
            type : 'hasOne',
            name: 'semaineType',
            model: 'AM.model.inscription.InscriptionSemaineTypeVO'
        },
    ]
    });

Ext.define('AM.model.inscription.CreneauType', 
{
    extend: 'Ext.data.Model',
    fields: 
        [
            {name: 'arrivee',      type: 'string'},
            {name: 'depart',      type: 'string'},
            {name: 'arrondi',      type: 'string'},
            {name: 'journeeType'},
            {name: 'uid',      type: 'string'},
            {name: 'id',      type: 'int'},
            {name: 'version',      type: 'int'}
        ],
        associations: 
        [
            {
                type : 'hasOne',
                name: 'journeeType',
                model: 'AM.model.inscription.JourneeType'
            },
        ],

});


最后,这就是我为创建这些模型所做的事情:

var newSemaine = Ext.create("AM.model.inscription.InscriptionSemaineTypeVO", {
                                                inscription : inscriptionId,
                                                id : -1,
                                            //'arrondiInMilli' : '',
                                            //'attributsVO' : '',
                                            //listeJourneesType : newJournee.data,
                                            //'tri' : '',
                                            //'id' : '',
                                            });

var newJournee = Ext.create("AM.model.inscription.JourneeType", {
                id :-2,
                arrondi : "00:00:00",
            });



var newCreneau = Ext.create("AM.model.inscription.CreneauType" ,{
            arrivee : "00:00:00",
            depart: "00:00:00",
            arrondi : "00:00:00",
            id : -3,
        });

            newJournee.set(
            {
                semaineType : newSemaine.data.id,
                listeCreneauxType : newCreneau.data,
            });

            newCreneau.set(
            {
//                  journeeType : newJournee.data.id,
                journeeType : -42,
            });

            newSemaine.set({
                listeJourneesType : newJournee.data,
            })


storeParents.getRange()[0].listeSemainesTypeStore.add(newSemaine);
storeParents.getRange()[0].setDirty(true);

我在 Jackson 的 github 上发现了一个问题,但似乎还没有修复...

知道如何坚持这一点吗?

提前谢谢你!(对不起,很长的帖子!

4

0 回答 0