spring jdbc does not convert java.sql.Date to java.time.LocalDate - spring-jdbc

The entity has one field, which type is LocalDate.
I am using Spring jdbcTemplate to query database and using BeanPropertyRowMapper to map the resultSet to the java object.
But spring does not convert java.sql.Date to java.time.LocalDate.
Here is the error message
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.sql.Date' to required type 'java.time.LocalDate' for property 'startDate';
nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.sql.Date] to required type [java.time.LocalDate] for property 'startDate': no matching editors or conversion strategy found

Related

Fill the nullable .net service method in AX2012

I want to set argument in a .net service methot. This method parameter type Nullable'1.
I create a method which name is findLastDate, return type of this method is TransDate. But when run the process take an error ;
System.NotSupportedException: DateTimeConverter cannot convert from Microsoft.Dynamics.Ax.Xpp.AxShared.utcdatetime.
Then i change findLastDate method's returntype to utcDateTime but unfortunately.
How can i fill this service method?
It looks like your issue isn't related to null but due to marshaling AX and CLR types.
See - https://learn.microsoft.com/en-us/dynamicsax-2012/developer/how-to-marshal-between-x-and-clr-primitive-types#code-sample-for-systemdatetime for how to marshal between the two.
I linked to the System.DateTime example in the article.

Elasticsearch NEST client datetime deserialization

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.

No parameterless constructor defined for an imported object type to be deserialized from JSON

Dim result = New JavaScriptSerializer().Deserialize(Of SearchResult)(Request.Cookies.Get("user").Value)
An exception of type 'System.MissingMethodException' occurred in System.Web.Extensions.dll but was not handled in user code
Additional information: No parameterless constructor defined for type of 'System.DirectoryServices.SearchResult'.
I see there have been many questions regarding this issue, but the required object types were self-defined class, so the solution would be to create a new and parameterless constructor for that class.
In my case, I am trying to use SearchResult from namespace System.DirectoryServices as the object type to be deserialized from JSON String. How can I solve it?
You can't deserialise a SearchResult object because it has no public constructor.
In theory you could write a JavaScriptConverter and use reflection to instantiate an instance of the target class in the convertor's Deserialize() method but that would be hackery of the first order.
Either serialize and deserialize a custom class of your own making, or rethink what you're doing.

Cannot deserialize an object using a converter?

Given a JSON string of the form {"$type":"MyType, MyAssembly","seed":0"}, why can't JsonConvert.DeserializeObject utilize the JsonConverter associated with "MyType"?
I've tried decorating the MyType class with a [JsonConverter(typeof(MyType))] attribute. Doesn't work. The custom JsonConverter's ReadJson method is never called.
I've tried adding the custom converter to the serializer's settings Converters collection and made sure the CanConvert method returns true for 'MyType' and the CanRead method returns true. Doesn't work. Neither the converter's CanConvert nor its ReadJson method is ever called.
The DeserializeObject method needs to be able to deserialize a JSON string containing an object whose type is unknown at compile time, but whose type is embedded in the JSON object via the special "$type" member. So don't suggest using DeserializeObject<T> or point out that it works for members, whose type is identified in the contract before hand.
FYI, this problem generalizes to cases where the deserialization needs to identify the object type solely from the embedded "$type" member, so for example, it also fails to resolve a converter if the JSON object is in an untyped JSON array, not just at the top-level.
Basically, an object cannot survive a round trip through the serialization/deserialization process, because although the WriteJson method will be called for the Converter when SerializeObject is called, when you subsequently pass the JSON string to DeserializeObject, it fails to call the converter's ReadJson method, and instead constructs an new instance and uses the basic member population routines.

Register parameter by name in Unity

With Unity, is it possible to register a parameter by name? My use case is the following. I want to register a value of type DateTime named "asOfDate" such that for any type that has a dependency on DateTime with constructor parameter named "asOfDate", Unity will serve an instance of DateTime equal to the registered value
No, this is not possible out of the box. Unity does not rely on the parameter name. So when any class expects a DateTime as constructor-parameter then the Unity container will use the registered one, regardless of the parameter name.
To have only certain types injected a special DateTime and others DateTime.Now, you have to register the common DateTime the usual way:
container.RegisterType<DateTime>();
The special object has be to registered using a name:
container.RegisterInstance<DateTime>("special", DateTime.Now);
Now when you want to have the special DateTime instance used when resolving an object you can register this object as follows:
container.RegisterType<IMyType, MyType>(
new InjectionConstructor(new ResolvedParameter<DateTime>("special"));

Resources