Skip to content

Commit 60a5493

Browse files
committed
made PGgeometry serializable again
usage of BinaryParser as local field made PGgeometry itself not serializable, removed field and inlined only usage Test Case added fixes #47
1 parent 1102828 commit 60a5493

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

jdbc/src/main/java/org/postgis/PGgeometry.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* PGgeometry.java
3-
*
3+
*
44
* PostGIS extension for PostgreSQL JDBC driver - PGobject Geometry Wrapper
5-
*
5+
*
66
* (C) 2004 Paul Ramsey, [email protected]
7-
*
7+
*
88
* (C) 2005 Markus Schaber, [email protected]
9-
*
9+
*
1010
* (C) 2015 Phillip Ross, [email protected]
1111
*
1212
* This library is free software; you can redistribute it and/or
@@ -22,7 +22,7 @@
2222
* You should have received a copy of the GNU Lesser General Public
2323
* License along with this library; if not, write to the Free Software
2424
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25-
*
25+
*
2626
*/
2727

2828
package org.postgis;
@@ -37,7 +37,6 @@ public class PGgeometry extends PGobject {
3737
private static final long serialVersionUID = 0x100;
3838

3939
Geometry geom;
40-
BinaryParser bp = new BinaryParser();
4140

4241
public PGgeometry() {
4342
this.setType("geometry");
@@ -54,7 +53,7 @@ public PGgeometry(String value) throws SQLException {
5453
}
5554

5655
public void setValue(String value) throws SQLException {
57-
geom = geomFromString(value, bp);
56+
geom = geomFromString(value, new BinaryParser());
5857
}
5958

6059
public static Geometry geomFromString(String value) throws SQLException {
@@ -131,7 +130,7 @@ public Geometry getGeometry() {
131130
public void setGeometry(Geometry newgeom) {
132131
this.geom = newgeom;
133132
}
134-
133+
135134
public int getGeoType() {
136135
return geom.type;
137136
}
@@ -153,7 +152,7 @@ public Object clone() {
153152

154153
/**
155154
* Splits a String at the first occurrence of border character.
156-
*
155+
*
157156
* Poor man's String.split() replacement, as String.split() was invented at
158157
* jdk1.4, and the Debian PostGIS Maintainer had problems building the woody
159158
* backport of his package using DFSG-free compilers. In all the cases we
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.postgis;
2+
3+
import org.testng.Assert;
4+
import org.testng.annotations.Test;
5+
6+
import java.io.ByteArrayOutputStream;
7+
import java.io.NotSerializableException;
8+
import java.io.ObjectOutputStream;
9+
10+
public class SerializationTest {
11+
12+
@Test
13+
public void serializationCheckPGgeometry() throws Exception {
14+
try {
15+
new ObjectOutputStream(new ByteArrayOutputStream())
16+
.writeObject(new PGgeometry("MULTIPOLYGON(((1 1,1 2,2 1,1 1)))"));
17+
}
18+
catch (NotSerializableException ex) {
19+
Assert.fail("serialization of PGgeometry failed: " + ex);
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)