GeoTools
  1. GeoTools
  2. GEOT-4100

NoSuchMethodException with GeometryJSON.read()

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 8.0-M0
    • Fix Version/s: 8.1, 9.0-M0
    • Component/s: geojson
    • Labels:
      None

      Description

      Parsing a valid geojson document with the following:
      GeometryJSON parser = new GeometryJSON(15);
      parser.read(geoJson);

      Throws a

      NoSuchMethodException: org.geotools.geojson.feature.FeatureHandler.<init>(com.vividsolutions.jts.geom.GeometryFactory)

      Note: We're using vividsolutions.jts version 1.11

        Activity

        Hide
        Justin Deoliveira added a comment -
        Seems to me like a classpath issue? Any chance you have an older version of the geotools libraries lying around?
        Show
        Justin Deoliveira added a comment - Seems to me like a classpath issue? Any chance you have an older version of the geotools libraries lying around?
        Hide
        Andre Lison added a comment - - edited
        Hi,
        I had the same problem and did some digging in the code.
        It turned out, that it is not a classpath issue:

        In the method "createDelegate" in org.geotools.geojson.DelegatingHandler are delegates created by using Reflection. The classes to instantiate are defined in a hash map further up. All the classes need a constructor with a single parameter of type GeometryFactory (see also "GeometryHandler" which calls the "createDelegate" and defines the constructor parameters). That works fine for "normal" json. When the json contains "feature"s, the DelegatingHandler tries to instantiate the FeatureHandler, which fails because FeatureHandler has only one constructor which takes a SimpleFeatureBuilder and AttributeIO, thus the instantiation fails and the above Exception is thrown.

        I did not had time to fix the issue but maybe my findings help someone else to do it.
        Show
        Andre Lison added a comment - - edited Hi, I had the same problem and did some digging in the code. It turned out, that it is not a classpath issue: In the method "createDelegate" in org.geotools.geojson.DelegatingHandler are delegates created by using Reflection. The classes to instantiate are defined in a hash map further up. All the classes need a constructor with a single parameter of type GeometryFactory (see also "GeometryHandler" which calls the "createDelegate" and defines the constructor parameters). That works fine for "normal" json. When the json contains "feature"s, the DelegatingHandler tries to instantiate the FeatureHandler, which fails because FeatureHandler has only one constructor which takes a SimpleFeatureBuilder and AttributeIO, thus the instantiation fails and the above Exception is thrown. I did not had time to fix the issue but maybe my findings help someone else to do it.
        Hide
        Justin Deoliveira added a comment -
        OK, it should be harmless to add the default constructors to those classes but if you are parsing a feature collection the intended method is to use the FeatureJSON class. If you don't know whether it will be straight geometry json or feature json then its tricky... the parser does't really handle this yet.
        Show
        Justin Deoliveira added a comment - OK, it should be harmless to add the default constructors to those classes but if you are parsing a feature collection the intended method is to use the FeatureJSON class. If you don't know whether it will be straight geometry json or feature json then its tricky... the parser does't really handle this yet.

          People

          • Assignee:
            Justin Deoliveira
            Reporter:
            Shahak Nagiel
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: