Announcement

Collapse
No announcement yet.

Serializable Angle, LatLon, Position

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Serializable Angle, LatLon, Position

    Hi, all. I have a feature request, but wasn't sure if it's valid. Would it be possible to make Angle, LatLon, and Position implement Serializable? I find it quite handy to use them in various classes in my app as basic location types, but one requirement I have is that my classes must be serializable. I've been messing around with setting up serialization proxies for them, but can't find a solution that would be as elegant as just having an "implements Serializable" added to those three classes. If need be, I'd be happy to log an issue/pull request on GitHub, just thought I'd check here first if this made sense.

  • #2
    I second this. I've had to hack around these classes to make them serialize by making "wrapper" classes with a default constructor. Very hacky:

    Code:
    class SerializablePosition implements Serializable {
    
        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 1L;
    
        transient private Position position;
    
        public SerializablePosition() {
    
        }
    
        public SerializablePosition(Position positionVal) {
            this.position = positionVal;
        }
    
        public Position getPosition() {
            return position;
        }
    
    
        private void writeObject(final java.io.ObjectOutputStream out)
                throws IOException {
    
            out.writeDouble(position.latitude.getDegrees());
            out.writeDouble(position.longitude.getDegrees());
            out.writeDouble(position.getAltitude());
    
        }
    
        private void readObject(final java.io.ObjectInputStream in)
                throws IOException {
    
            try {
                in.defaultReadObject();
                final double lat = in.readDouble();
                final double lon = in.readDouble();
                final double alt = in.readDouble();
    
                position = Position.fromDegrees(lat, lon, alt);
    
            } catch (final ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        }
    
    }

    Comment

    Working...
    X