public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> wholeDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            Dictionary<string, object> facetDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(wholeDict.First().Value.ToString());
            Dictionary<string, object> geoDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(facetDict.GetString(FacetTypeEnum.GeoDistance.ToString()));

            List<DistanceBucket> rangeBuckets = new List<DistanceBucket>();
            string rangeBucketsJson = null;
            if (geoDict.ContainsKey(_RANGES))
            {
                rangeBucketsJson = geoDict.GetString(_RANGES);
            }
            else
            {
                throw new RequiredPropertyMissingException(_RANGES);
            }

            foreach (Dictionary<string, object> bucketDict in JsonConvert.DeserializeObject<IEnumerable<Dictionary<string, object>>>(rangeBucketsJson))
            {
                DistanceBucket bucket = new DistanceBucket();
                if (bucketDict.ContainsKey(_GREATER_THAN))
                    bucket.GreaterThan = bucketDict.GetDouble(_GREATER_THAN);
                if (bucketDict.ContainsKey(_LESS_THAN))
                    bucket.LessThan = bucketDict.GetDouble(_LESS_THAN);
                if (bucketDict.ContainsKey(_GREATER_THAN_OR_EQUAL))
                    bucket.GreaterThanOrEqualTo = bucketDict.GetDouble(_GREATER_THAN_OR_EQUAL);
                if (bucketDict.ContainsKey(_LESS_THAN_OR_EQUAL))
                    bucket.LessThanOrEqualTo = bucketDict.GetDouble(_LESS_THAN_OR_EQUAL);

                rangeBuckets.Add(bucket);
            }

            KeyValuePair<string, object> fieldKvp = geoDict.FirstOrDefault(x => !_KnownFields.Contains(x.Key, StringComparer.OrdinalIgnoreCase));
            if (string.IsNullOrWhiteSpace(fieldKvp.Key))
                throw new RequiredPropertyMissingException("field");

            GeoDistanceFacet facet = new GeoDistanceFacet(
                wholeDict.First().Key,
                fieldKvp.Key,
                CoordinatePointSerializer.DeserializeCoordinatePoint(fieldKvp.Value.ToString()),
                rangeBuckets);

            facet.ValueField = geoDict.GetStringOrDefault(_VALUE_FIELD);
            facet.ValueScript = geoDict.GetStringOrDefault(_VALUE_SCRIPT);
            if (geoDict.ContainsKey(_PARAMETERS))
            {
                facet.ScriptParameters = JsonConvert.DeserializeObject<ScriptParameterCollection>(geoDict.GetString(_PARAMETERS));
            }
            facet.ScriptLanguage = geoDict.GetStringOrDefault(_LANGUAGE);

            return facet;
        }
        public void PASS_Serialize()
        {
            GeoDistanceFacet facet = new GeoDistanceFacet("name", "field",
                new CoordinatePoint("asdfasdf"),
                new List<DistanceBucket>()
                {
                    new DistanceBucket()
                    {
                        GreaterThan = 5,
                        LessThan = 10
                    }
                });

            string json = JsonConvert.SerializeObject(facet);
            Assert.IsNotNull(json);

            string expectedJson = "{\"name\":{\"geo_distance\":{\"field\":\"asdfasdf\",\"ranges\":[{\"gt\":5.0,\"lt\":10.0}]}}}";
            Assert.AreEqual(expectedJson, json);
        }
        public void PASS_Create()
        {
            GeoDistanceFacet facet = new GeoDistanceFacet("name", "field",
                new CoordinatePoint("asdfasdf"),
                new List<DistanceBucket>()
                {
                    new DistanceBucket()
                    {
                        GreaterThan = 5,
                        LessThan = 10
                    }
                });

            Assert.IsNotNull(facet);
            Assert.AreEqual("name", facet.FacetName);
            Assert.AreEqual("field", facet.Field);
            Assert.AreEqual("asdfasdf", facet.CenterPoint.GeoHash);
            Assert.AreEqual((double)5, facet.RangeBuckets.First().GreaterThan);
            Assert.AreEqual((double)10, facet.RangeBuckets.First().LessThan);
        }