Skip to content

Commit

Permalink
Fixing the serialization of Point fields to GeoJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
computate committed Jan 11, 2024
1 parent 10a86a8 commit bea283f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
31 changes: 7 additions & 24 deletions src/main/java/org/computate/frFR/java/EcrireGenClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3703,31 +3703,10 @@ else if(entiteSetUpper)
staticSet = true;
}

// Setter Point //
if(StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePoint)) {
tl(1, "@JsonIgnore");
tl(1, "public void set", entiteVarCapitalise, "(String o) {");
tl(2, "this.", entiteVar, " = ", classeNomSimple, ".staticSet", entiteVarCapitalise, "(", classeContientRequeteSite ? (langueConfig.getString(ConfigCles.var_requeteSite) + "_") : "null", ", o);");
tl(1, "}");
tl(1, "public static ", entiteNomSimpleComplet, " staticSet", entiteVarCapitalise, "(", classePartsRequeteSite.getEtendBase() ? classePartsRequeteSite.getNomSimpleSuperGenerique() : classePartsRequeteSite.nomSimple(langueNom), " ", langueConfig.getString(ConfigCles.var_requeteSite), "_, String o) {");
tl(2, "if(o != null) {");
tl(3, "Matcher m = Pattern.compile(\"\\\\{[\\\\w\\\\W]*\\\"coordinates\\\"\\\\s*:\\\\s*\\\\[\\\\s*(\\\\d*\\\\.\\\\d*)\\\\s*,\\\\s*(\\\\d*\\\\.\\\\d*)\\\\]\").matcher(o);");
tl(3, "if(m.find())");
tl(4, "return new Point(Double.parseDouble(m.group(1)), Double.parseDouble(m.group(2)));");
tl(3, "m = Pattern.compile(\"\\\\s*(\\\\d*\\\\.\\\\d*)\\\\s*,\\\\s*(\\\\d*\\\\.\\\\d*)\").matcher(o);");
tl(3, "if(m.find())");
tl(4, "return new Point(Double.parseDouble(m.group(1)), Double.parseDouble(m.group(2)));");
tl(3, "throw new RuntimeException(String.format(\"Invalid point format \\\"%s\\\", try these formats instead: 55.633703,13.49254 or {\\\"type\\\":\\\"Point\\\",\\\"coordinates\\\":[55.633703,13.49254]}\", o));");
tl(2, "}");
tl(2, "return null;");
tl(1, "}");
staticSet = true;
}

// Setter Path //
if(
StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePath) || StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePolygon)
|| StringUtils.equals(entiteNomCanoniqueGenerique, VAL_nomCanoniquePath) || StringUtils.equals(entiteNomCanoniqueGenerique, VAL_nomCanoniquePolygon)
StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePoint) || StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePath) || StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePolygon)
|| StringUtils.equals(entiteNomCanoniqueGenerique, VAL_nomCanoniquePoint) || StringUtils.equals(entiteNomCanoniqueGenerique, VAL_nomCanoniquePath) || StringUtils.equals(entiteNomCanoniqueGenerique, VAL_nomCanoniquePolygon)
) {
tl(1, "@JsonIgnore");

Expand Down Expand Up @@ -3772,7 +3751,11 @@ else if(entiteSetUpper)
tl(2, "if(o != null) {");
tl(3, "try {");
tl(4, entiteNomCanoniqueGenerique == null ? entiteNomSimple : entiteNomSimpleGenerique, " shape = new ", entiteNomCanoniqueGenerique == null ? entiteNomSimple : entiteNomSimpleGenerique, "();");
if(StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePath) || StringUtils.equals(entiteNomCanoniqueGenerique, VAL_nomCanoniquePath)) {
if(StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePoint) || StringUtils.equals(entiteNomCanoniqueGenerique, VAL_nomCanoniquePoint)) {
tl(4, "JsonArray coordinates = o.getJsonArray(\"coordinates\");");
tl(4, "shape.setX(coordinates.getDouble(0));");
tl(4, "shape.setY(coordinates.getDouble(1));");
} else if(StringUtils.equals(entiteNomCanonique, VAL_nomCanoniquePath) || StringUtils.equals(entiteNomCanoniqueGenerique, VAL_nomCanoniquePath)) {
tl(4, "o.getJsonArray(\"coordinates\").stream().map(a -> (JsonArray)a).forEach(points -> {");
tl(5, "shape.addPoint(new Point(Double.parseDouble(points.getString(0)), Double.parseDouble(points.getString(1))));");
tl(4, "});");
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/computate/frFR/java/IndexerClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2947,8 +2947,8 @@ else if(entiteClasseParts != null && entiteClasseParts.getDocumentSolr() != null
}

if(
"Path".equals(entiteNomSimple) || "Polygon".equals(entiteNomSimple)
|| "Path".equals(entiteNomSimpleGenerique) || "Polygon".equals(entiteNomSimpleGenerique)
"Point".equals(entiteNomSimple) || "Path".equals(entiteNomSimple) || "Polygon".equals(entiteNomSimple)
|| "Point".equals(entiteNomSimpleGenerique) || "Path".equals(entiteNomSimpleGenerique) || "Polygon".equals(entiteNomSimpleGenerique)
) {
classePartsGenAjouter(ClasseParts.initClasseParts(this, "com.fasterxml.jackson.databind.ObjectMapper", classeLangueNom), classeLangueNom);
classePartsGenAjouter(ClasseParts.initClasseParts(this, "com.fasterxml.jackson.databind.module.SimpleModule", classeLangueNom), classeLangueNom);
Expand Down Expand Up @@ -3705,8 +3705,8 @@ else if(StringUtils.equalsAny(entiteNomCanonique, VAL_nomCanoniqueLong)) {
entiteNomCanoniqueVertxJson = VAL_nomCanoniqueString;
}
else if(StringUtils.equalsAny(entiteNomCanonique, VAL_nomCanoniquePoint)) {
entiteNomSimpleVertxJson = "String";
entiteNomCanoniqueVertxJson = VAL_nomCanoniqueString;
entiteNomSimpleVertxJson = "JsonObject";
entiteNomCanoniqueVertxJson = VAL_nomCanoniqueVertxJsonObject;
}
else if(StringUtils.equalsAny(entiteNomCanonique, VAL_nomCanoniquePath)) {
entiteNomSimpleVertxJson = "JsonObject";
Expand Down Expand Up @@ -4146,9 +4146,9 @@ else if(StringUtils.equalsAny(entiteNomCanonique, VAL_nomCanoniqueLong)) {
entiteFormatHtm = "integer";
}
else if(StringUtils.equalsAny(entiteNomCanonique, VAL_nomCanoniquePoint)) {
entiteTypeJson = "string";
entiteTypeJson = "object";
if(entiteFiwareType == null)
entiteFiwareType = "string";
entiteFiwareType = "object";
entiteNgsiType = "GeoProperty";
if(entiteFormatHtm == null)
entiteFormatHtm = "default";
Expand Down

0 comments on commit bea283f

Please sign in to comment.