Elasticsearch NEST client datetime deserialization - datetime

I'm trying to deserialize my NEST document to datetime, but everything ends up being a string because I'm using System.Object:
var response = this.client.Search<object>(search);
The reason for this is because I'm searching multiple indices and I have to use object type. Since my whole application is returning DateFormatHandling.MicrosoftDateFormat.
I'd like NEST to deserialize datetime to DateTime type, so that my serializer can correctly serialize to MicrosoftDateFormat on API.

Related

Using json mappers to retrieve and save data with firestore?

I'm trying to use json mappers to handle my Flutter Firebase Firestore serialization and deserialization. Right now I'm using the json_serializable package, which has gotten me past most hurdles.
I'm seeing an issue when inserting / updating though. I have to be able to get my dart object into the json Map form, not the String form to properly insert it. While the library provides a Map<String, dynamic> toJson() => ... function implementation, this function doesn't convert nested objects, which basically makes it worthless.
To work around this I'm converting the json into a String, then back into a Map doing the following:
final json = jsonEncode(reg);
final jsonMap = jsonDecode(json);
This is obviously bad. How can I get my dart object into a json Map form better?
I'm also having to do weird things, like grab the snapshot data, and grab the document id, and then insert the id into the data map before deserializing it, so I have the id in the data model, and then remove it before serializing. There has to be a better way to auto-serialize and deserialize from firebase. What am I missing?
final snapshot = document.data;
snapshot['id'] = documentID;

Change serializer for WebMethod from JsonDataContractSerializer to NewtonSoft Json Serializer

If I return an object containing a DateTime property from a web method, which would be methods prefix with the data annotation
[WebMethod]
that date will be serialized to something like
"/Date(1365776562553)/"
instead of a string in iso-8601 format like
"2013-04-12T19:59:53.2422758+05:30"
If I could change the serializer for web methods from JsonDataContractSerializer to NewtonSoft Json Serializer, the dates would be fixed.
How?
I will not serialize manually or writing javascripts that consumes date strings in the first format.
The googling I have done this far only directs me to pages where any of those workarounds are suggested.

Dart - HTTP - Encode JSON Object with Array & int properties

I'm trying to make a POST request using dart's http package with json data as the body, I'm using a variable of type dynamic to create the json object and so far it works perfectly as long as all the values in the object are strings.
If I assign the value of a property to be an int or List<int> (expecting it to be converted to an array, as expected by the server) dart crashes due to expecting either a Map<String, String> or a List<int> as the type for the body (the exact type it expects is dynamic, but it tries to cast it to Map<String, String> or List<int>).
My question is, is there any workaround to making a http POST request in dart using a object with dynamic property values?
I was able to resolve this issue by using the HttpClient & HttpClientRequest classes from the dart:io package.
I stored the body as a Map<String, dynamic> and json encoded it before writing it to the request stream.

How to get all SolrNet query result info in JSON format?

I am not sure if this is a JSON.Net issue or a SolrNet issue, which is why I am tagging it with both.
I am using SolrNet and currently handling all page interactivity with JavaScript from an MVC call, by returning a JsonNetResult encoding of the object returned by solr.Query(). I am now experimenting with Faceting, but am not seeing the Facet info in my results.
I've got an MVC Controller method like the one below. (JsonNetResult is similar to the stock JsonResult, but encodes JSON using JSON.Net, described here.)
public JsonNetResult Index(string keywords)
{
JsonNetResult jsonNetResult = new JsonNetResult();
var documents = solr.Query(new SolrQuery(keywords), new QueryOptions
{
Rows = 10,
Facet = new FacetParameters
{
Queries = new[] {new SolrFacetFieldQuery("system")}
}
});
jsonNetResult.Formatting = Formatting.Indented;
jsonNetResult.Data = documents;
return jsonNetResult;
}
I was expecting to see the faceting information encoded into JSON in the JsonNetResult, but all it contains is the array of hashes of the documents matching my query. Am I missing something in how SolrNet response objects work, or do I really need to parse through the object myself, and create something that JSON.Net can use to encode all of the information related to my query?
FYI, I have tried using a standard JsonResult in MVC, and the results are the same. Also, the reason I am using SolrNet and not just calling Solr directly and asking for JSON is because we do not want to expose the Solr search engine web interface directly to the user.
Since Solr can respond with JSON, if you want to return JSON directly to the view you'd be incurring some unnecessary overhead by having SolrNet deserialize a XML response, then serialize it to JSON. Instead, use SolrNet's components to skip the response parser. A couple of pointers to do this:
SolrQueryExecuter.GetAllParameters()
Low-level SolrNet
I am not sure if this is the best answer, but I have since been experimenting and found that if I change my original line from:
jsonNetResult.Data = documents;
to:
jsonNetResult.Data = new { Documents = documents, FacetFields = documents.FacetFields };
The data is at least serialized by JSON.Net. I guess I still don't understand the format of the object being returned by SolrNet's Query() method, since it seems like those properties (like FacetFields) should be serialized without me having to explicitly name them like I'm now doing above?

XmlSerializer, deserializing time only into DateTime type

My WCF uses XmlSerializer to serialize and deserialize fairly complex objects. Problem is, the corresponding XML payload value of one of the DateTime properties could be specified as either xs:date, xs:time or xs:dateTime values. I've noticed that when a time-only value (e.g. 16:55:00Z) is specified in the input XML the current date gets 'prepended' during deserialization (e.g. 2010-12-13T16:55:00Z). This obviously creates false data, I would rather have preferred DateTime.MinValue.
Is there a way I can control this behavior?
Thanks in advance
We use WCFDate to send the date part as xs:date.
See http://www.codeproject.com/Articles/182960/WCF-Support-for-xs-date for code.

Resources