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

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.12.0, 3.0.0
    • Component/s: JSON
    • None

      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));
      	}
      }
      

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

              Created:
              Updated:
              Resolved: