Linked Questions

Popular Questions

I have an object that I want to parse to XML. I manage to parse it but it does contain also some tagname/fieldname that I don't want:

This is how it looks right now:

<polygon>
        <pointList>
          <latitude>42.316</latitude>
          <longitude>-71.3914</longitude>
        </pointList>
        <pointList>
          <latitude>42.3158</latitude>
          <longitude>-71.3952</longitude>
        </pointList>
        <pointList>
          <latitude>42.3159</latitude>
          <longitude>-71.3968</longitude>
        </pointList>
 </polygon>

And I want it like this:

<polygon>42.316,-71.3914 42.3158,-71.3952 42.3159,-71.3968</polygon>

I have the classes defined like this:

@Data
@AllArgsConstructor
@NoArgsConstructor
@XmlRootElement(name = "area")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso(ArrayList.class)
public class Area {
    @XmlElement(name = "polygon")
    List<Polygon> polygonList = new ArrayList<>();

    public void addPolygon(Polygon polugon) {
        if (polygonCList == null) {
            throw new NullPointerException();
        }
        polygonCList.add(polugon);
    }
}
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@XmlRootElement(name = "polygon")
@XmlAccessorType(XmlAccessType.FIELD)
public class Polygon {
    List<Point> pointList = new ArrayList<>();
     
    public void addPoint(Point pointC) {
        if (pointC == null) {
            throw new NullPointerException();
        }
        pointCList.add(pointC);
    }
}

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Point {
    Double latitude = 0D;
    Double longitude = 0D;
}

And I was parsing using:

JAXBContext jaxbContext3 = JAXBContext.newInstance(Area.class);
Marshaller jaxbMarshaller3 = jaxbContext3.createMarshaller();
jaxbMarshaller3.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

axbMarshaller3.marshal(alert, document);

Is there a way to achieve that format?

Related Questions