@ Override public JsonElement serialize ( Point src , Type typeOfSrc , JsonSerializationContext context ) { JsonArray rawCoordinates = new JsonArray ( ) ; // Unshift coordinates List < Double > unshiftedCoordinates = CoordinateShifterManager . getCoordinateShifter ( ) . unshiftPoint ( src ) ; rawCoordinates . add ( new JsonPrimitive ( GeoJsonUtils . trim ( unshiftedCoordinates . get ( 0 ) ) ) ) ; rawCoordinates . add ( new JsonPrimitive ( GeoJsonUtils . trim ( unshiftedCoordinates . get ( 1 ) ) ) ) ; // Includes altitude if ( src . hasAltitude ( ) ) { rawCoordinates . add ( new JsonPrimitive ( unshiftedCoordinates . get ( 2 ) ) ) ; } return rawCoordinates ; }
Required to handle the special case where the altitude might be a Double . NaN which isn t a valid double value as per JSON specification .