Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1841

JSON serializer will write out Inifinity but JSON.parse fails to parse it

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 2.12.0, 3.0.0
    • JSON
    • None

    Description

      Infinity is not part of the JSON spec, but neither is NaN, and the Mongo driver's parser seems to handle that case so should it not also handle Infinity?

      This program demonstrates the problem.

      TestMongoInfinity.java

      public class TestMongoInfinity {
      	public static void test(BasicDBObject obj) {
      		String serializedObj = null;
      		try {
      			serializedObj = JSONSerializers.getStrict().serialize(obj);
      		} catch (Throwable t) {
      			System.out.println("Error during serialization");
      			t.printStackTrace();
      		}
      		BasicDBObject deserialized = null;
      		try {
      			deserialized = (BasicDBObject)JSON.parse(serializedObj);
      		} catch (Throwable t) {
      			System.out.println("Error during deserialization");
      			t.printStackTrace();
      		}
      	}
      	
      	public static void main(String[] args) {
      		test(new BasicDBObject("val", Double.POSITIVE_INFINITY));
      		test(new BasicDBObject("val", Double.NEGATIVE_INFINITY));
      	}
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            marpidone Matt Arpidone
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: