1

JTS ライブラリを使用しようとしていますが、Point プロパティを持つクラスをシリアル化する際に奇妙な問題が発生しています。

import java.io.IOException;
import java.io.Serializable;

import com.owlike.genson.Genson;
import com.owlike.genson.TransformationException;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.PrecisionModel;

public class TestJTS implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 7778701490986272036L;
    protected Point point = null;

    public TestJTS() {
        super();
    }

    /**
     * @param args
     */
    public static void main(String[] args) {

        TestJTS test = new TestJTS();
        GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
        Coordinate coordinate = new Coordinate(10.0, 100.1);
        Point point = gf.createPoint(coordinate);
        test.setPoint(point);

        System.out.println("Point: " + test.getPoint());

        Genson genson = new Genson();
        try {
            String json = genson.serialize(test);
            System.out.println(json);

        } catch (TransformationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public Point getPoint() {
        return point;
    }

    public void setPoint(Point point) {
        this.point = point;
    }
}

以下のこの最小限の例では例外が発生しますが、その理由がわかりません。私のコードは間違っていますか?JTS ライブラリの使用方法について間違った仮定をしていますか?

Point: POINT (10 100.1)
com.owlike.genson.TransformationException: Could not serialize property 'point' from class TestJTS
    at com.owlike.genson.reflect.PropertyAccessor.couldNotSerialize(PropertyAccessor.java:48)
    at com.owlike.genson.reflect.PropertyAccessor.serialize(PropertyAccessor.java:31)
    at com.owlike.genson.reflect.BeanDescriptor.serialize(BeanDescriptor.java:87)
    at com.owlike.genson.convert.NullConverter$NullConverterWrapper.serialize(NullConverter.java:51)
    at com.owlike.genson.Genson.serialize(Genson.java:341)
    at com.owlike.genson.Genson.serialize(Genson.java:222)
    at TestJTS.main(TestJTS.java:40)
Caused by: com.owlike.genson.TransformationException: Could not serialize property 'boundary' from class com.vividsolutions.jts.geom.Point
    at com.owlike.genson.reflect.PropertyAccessor.couldNotSerialize(PropertyAccessor.java:48)
    at com.owlike.genson.reflect.PropertyAccessor.serialize(PropertyAccessor.java:31)
    at com.owlike.genson.reflect.BeanDescriptor.serialize(BeanDescriptor.java:87)
    at com.owlike.genson.convert.NullConverter$NullConverterWrapper.serialize(NullConverter.java:51)
    at com.owlike.genson.convert.CircularClassReferenceConverterFactory$CircularConverter.serialize(CircularClassReferenceConverterFactory.java:30)
    at com.owlike.genson.reflect.PropertyAccessor.serialize(PropertyAccessor.java:29)
    ... 5 more
Caused by: com.owlike.genson.TransformationRuntimeException: Could not access value of property named 'boundary' using accessor public abstract com.vividsolutions.jts.geom.Geometry com.vividsolutions.jts.geom.Geometry.getBoundary() from class com.vividsolutions.jts.geom.Geometry
    at com.owlike.genson.reflect.PropertyAccessor.couldNotAccess(PropertyAccessor.java:42)
    at com.owlike.genson.reflect.PropertyAccessor$MethodAccessor.access(PropertyAccessor.java:72)
    at com.owlike.genson.reflect.PropertyAccessor.serialize(PropertyAccessor.java:26)
    at com.owlike.genson.reflect.BeanDescriptor.serialize(BeanDescriptor.java:87)
    at com.owlike.genson.convert.NullConverter$NullConverterWrapper.serialize(NullConverter.java:51)
    at com.owlike.genson.convert.CircularClassReferenceConverterFactory$CircularConverter.serialize(CircularClassReferenceConverterFactory.java:30)
    at com.owlike.genson.reflect.PropertyAccessor.serialize(PropertyAccessor.java:29)
    ... 9 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.owlike.genson.reflect.PropertyAccessor$MethodAccessor.access(PropertyAccessor.java:66)
    ... 14 more
Caused by: java.lang.IllegalArgumentException: This method does not support GeometryCollection arguments
    at com.vividsolutions.jts.geom.Geometry.checkNotGeometryCollection(Geometry.java:1782)
    at com.vividsolutions.jts.geom.GeometryCollection.getBoundary(GeometryCollection.java:154)
    ... 19 more

4

1 に答える 1