@@ -64,41 +64,36 @@ public Object objectDone(){
6464 BSONObject b = (BSONObject )o ;
6565
6666 // override the object if it's a special type
67- if ( ! _lastArray ) {
68- if ( b .containsField ( "$oid" ) ) {
69- o = new ObjectId ((String )b .get ("$oid" ));
70- if (!isStackEmpty ()) {
71- gotObjectId ( name , (ObjectId )o );
72- } else {
73- setRoot (o );
74- }
75- } else if ( b .containsField ( "$date" ) ) {
76- SimpleDateFormat format =
77- new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
78- GregorianCalendar calendar = new GregorianCalendar (new SimpleTimeZone (0 , "GMT" ));
79- format .setCalendar (calendar );
67+ if (!_lastArray ) {
68+ if (b .containsField ("$oid" )) {
69+ o = new ObjectId ((String ) b .get ("$oid" ));
70+ if (!isStackEmpty ()) {
71+ gotObjectId (name , (ObjectId ) o );
72+ } else {
73+ setRoot (o );
74+ }
75+ } else if (b .containsField ("$date" )) {
8076
81- String txtdate = b .get ("$date" ).toString ();
77+ if (b .get ("$date" ) instanceof Number ){
78+ o = new Date (((Number )b .get ("$date" )).longValue ());
79+ }else {
80+ SimpleDateFormat format = new SimpleDateFormat (_msDateFormat );
81+ format .setCalendar (new GregorianCalendar (new SimpleTimeZone (0 , "GMT" )));
82+ o = format .parse (b .get ("$date" ).toString (), new ParsePosition (0 ));
8283
83- try {
84- // Convert from seconds to ms to match consistency
85- // with strict JSON serialization
86- o = new Date ( Long .parseLong (txtdate ) * 1000l );
87- } catch (NumberFormatException e ) {
88- o = format .parse (txtdate , new ParsePosition (0 ));
8984 if (o == null ) {
9085 // try older format with no ms
91- format = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" );
92- format .setCalendar (calendar );
93- o = format .parse (txtdate , new ParsePosition (0 ));
86+ format = new SimpleDateFormat (_secDateFormat );
87+ format .setCalendar (new GregorianCalendar ( new SimpleTimeZone ( 0 , "GMT" )) );
88+ o = format .parse (b . get ( "$date" ). toString () , new ParsePosition (0 ));
9489 }
9590 }
96- if (!isStackEmpty ()) {
97- cur ().put ( name , o );
98- } else {
99- setRoot (o );
100- }
101- } else if ( b .containsField ( "$regex" ) ) {
91+ if (!isStackEmpty ()) {
92+ cur ().put (name , o );
93+ } else {
94+ setRoot (o );
95+ }
96+ } else if ( b .containsField ( "$regex" ) ) {
10297 o = Pattern .compile ( (String )b .get ( "$regex" ),
10398 BSON .regexFlags ( (String )b .get ( "$options" )) );
10499 if (!isStackEmpty ()) {
@@ -158,6 +153,9 @@ public Object objectDone(){
158153 }
159154 return o ;
160155 }
161-
156+
162157 private boolean _lastArray = false ;
158+
159+ public static final String _msDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ;
160+ public static final String _secDateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" ;
163161}
0 commit comments