Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Moxy - Conditional attribute mapping?


Hi.

        XMLDirectMapping point = new XMLDirectMapping();
        point.setAttributeName("position");
        point.setField(new XMLField("defect:geographicLocation/gml:Point/gml:pos/text()"));
        point.setConverter(new PositionConverter());
        defectNotificationEvent.addMapping(point);

        XMLDirectMapping gmlId = new XMLDirectMapping();
        gmlId.setAttributeName("gmlId");
        gmlId.setXPath("defect:geographicLocation/gml:Point/@gml:id");
        defectNotificationEvent.setPrimaryKeyFieldName("@gml:id");
        defectNotificationEvent.addMapping(gmlId);

If position is null, the first mapping generates no xml. The second mapping however, adds a gml id. But I only want it to add this gml id if position is not null. Is there a way to do this in the mapping? Right now I added a set/getGmlId where I return null is position is null, and gmlid otherwise.

--

  /Magnus Heino

Back to the top