code: private Collection<Geometry> restoreDim4(Collection<Geometry> geoms, Map<Coordinate, Double> map) {
          GeometryFactory factory = new GeometryFactory(
                  new PackedCoordinateSequenceFactory(PackedCoordinateSequenceFactory.DOUBLE, 4));
          Collection<Geometry> result = new ArrayList<>();
          for (Geometry geom : geoms) {
              if (geom instanceof Point) {
                  result.add(factory.createPoint(restoreDim4(
                          ((Point) geom).getCoordinateSequence(), map)));
              } else if (geom instanceof LineString) {
                  result.add(factory.createLineString(restoreDim4(
                          ((LineString) geom).getCoordinateSequence(), map)));
              } else if (geom instanceof Polygon) {
                  LinearRing outer = factory.createLinearRing(restoreDim4(
                          ((Polygon) geom).getExteriorRing().getCoordinateSequence(), map));
                  LinearRing[] inner = new LinearRing[((Polygon) geom).getNumInteriorRing()];
                  for (int i = 0; i < ((Polygon) geom).getNumInteriorRing(); i++) {
                      inner[i] = factory.createLinearRing(restoreDim4(
                              ((Polygon) geom).getInteriorRingN(i).getCoordinateSequence(), map));
                  }
                  result.add(factory.createPolygon(outer, inner));
              } else {
                  for (int i = 0; i < geom.getNumGeometries(); i++) {
                      result.addAll(restoreDim4(Collections.singleton(geom.getGeometryN(i)), map));
                  }
              }
          }
          return result;
      }
docs: Use ring to restore M values on geoms