使用Jackson在EXTJS中创建循环模型集群的问题

时间:2013-08-14 13:34:12

标签: extjs jackson

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

会产生以下问题:

  

错误fr.package.extjs.web.controller.AbstractSpringController - ERROR on   inscriptionDetail.validerInscription   org.springframework.http.converter.HttpMessageNotReadableException:无法读取JSON:无法解析对象ID [-42](对于[simple type,class]   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:无法解析Object Id [-42](对于[simple type,class fr.package.app.inscription.vo.InscriptionJourneeTypeVO]) - unresolved forward-reference? (通过参考链: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”])       at 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上发现了一个问题,但似乎还没有修复......

我知道如何坚持下去吗?

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

0 个答案:

没有答案