jsonserializer

How to deserialize asp.net datetime as JSON datetime with client's timezone

ぃ、小莉子 提交于 2019-12-12 06:16:08
问题 I'm struggling with datetimes a bit. I'm using asp.net mvc api controllers, a microsoft sql server and AngularJS. On some button click I'm sending a JSON formatted date to an api-controller. When I post 2015-11-31 00:00 and I look in Fiddler to see what's really posted, I see that the date is formatted as such: 2015-11-30T23:00:00.000Z. (2015-11-31 - 1 hour UTC+01:00 Amsterdam, Berlin, Ber....) This is perfect because there might be a difference between the timezone the sql server might be in

C# DataMember Serializer Ordering Opposite of Expected

三世轮回 提交于 2019-12-12 04:58:56
问题 According to this article, I'd expect to see the fields in my base class at the top of the list of fields when serializing to JSON. However, I'm seeing the fields at the bottom of the list. The ordering is correct within the actual class itself, but not among the hierarchy. What's happening is it's ordering properly with the class, it it's doing the exact reverse of what I'd expect. I'd expect the base classes to have their fields serialized first. I don't want to use the Order=X attribute

Why are DriveInfo's properties missing when serializing to json string using Json.NET?

試著忘記壹切 提交于 2019-12-12 00:40:13
问题 Attempting to serialize DrivInfo to a Json string with this code only return the "name" property: DriveInfo dr = new DriveInfo("C"); string json = Newtonsoft.Json.JsonConvert.SerializeObject(dr); The string result is only: {"_name":"C:\"} DrivInfo is sealed so I cannot change anything. Is there a way to do it excluding wrapping? 回答1: The class contains its own custom serialization which specifies that only the _name field should be included. The other properties aren't stored in the class.

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value did not match expected type java.time.LocalDateTime

…衆ロ難τιáo~ 提交于 2019-12-11 15:44:05
问题 I just started to take care of a code developed by other person. It was designed based on Specification pattern using Spring Data and Hibernate. In few words, if I try search using string, boolean or integer fields it works correctly. For instance, when I search/filter with state==SP I got the result and I can see that the diatomite fields are correctly filled in. Also I see hibernate no complaining about invalid data in this case: Copied form my console when I searched succesfully with

Json() in MVC converts datetime to UTC automatically

落花浮王杯 提交于 2019-12-11 14:13:38
问题 I am already storing UTC time in DateTime objects. When I send this across using Json() serializer these dates are again converted to UTC. I don't want this to happen. Please help. 回答1: Check the Kind property of your DateTime objects, maybe they are not marked as UTC then they get converted again. 来源: https://stackoverflow.com/questions/10138562/json-in-mvc-converts-datetime-to-utc-automatically

Serializing a model which has a foreign key to Django Auth User

╄→尐↘猪︶ㄣ 提交于 2019-12-11 05:42:41
问题 How can one serialize a model which has a foreign key to Django auth user so that a username can be retrieved? This is what I have tried through Tastypie: def dehydrate(self, bundle): posts = Post.objects.annotate(num_poster = Count('likedby')).order_by('-num_poster') specificpost = posts.get(id__exact=bundle.data['id']) likedList = specificpost.likedby.all()[:7] liked_data = serializers.serialize('python', likedList, fields=('user__username', 'userPic'), use_natural_keys=True) liked_actual =

Web API - JsonConverter - Custom Attribute

微笑、不失礼 提交于 2019-12-11 01:52:33
问题 We are having a web api project and inorder to convert the date time to date and vice versa, we are using DateTimeconverter extended from JsonConverter. We are using this in the form of an attribute for all the required DateTime properties (as shown below): [JsonConverter(typeof(CustomDateConverter))] The CustomDateConverter is as below: public class CustomDateConverter: JsonConverter { private string[] formats = new string[] { "yyyy-MM-dd", "MM/dd/yy", "MM/dd/yyyy", "dd-MMM-yy" }; public

Jil serializer ignore null properties

孤街醉人 提交于 2019-12-11 01:06:01
问题 Is there an attribute to prevent Jil from serializing properties that are null ? In Newtonsoft it is : [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] 回答1: For the whole object, the excludeNulls parameter on Options is what you want (many different Options configurations are pre-calced, anything like Options.ExcludeNulls also works). You can control serialization of a single property with Conditional Serialization. (I forgot about this option in my original answer). For example

How i can recover a Map of objects from json?

徘徊边缘 提交于 2019-12-10 22:37:14
问题 I have this class public static class SomeClass { public SomeClass(String field) { this.field = field; } private final String field; public String getField() { return field; } } I have also this test ( edited ) @Test public void testStringifyMapOfObjects() { Map<String, SomeClass> original = Maps.newTreeMap(); original.put("first", new SomeClass("a")); original.put("second", new SomeClass("b")); String encoded = JsonUtil.toJson(original); Map<String, SomeClass> actual = JsonUtil.fromJson

laravel Interface 'JsonSerializable' not found

。_饼干妹妹 提交于 2019-12-10 14:31:51
问题 Im using the following for my application for social media login https://github.com/madewithlove/laravel-oauth2 but im getting this error Symfony \ Component \ Debug \ Exception \ FatalErrorException Interface 'JsonSerializable' not found open: /Applications/AMPPS/www/docsearch/vendor/madewithlove/laravel-oauth2/src/OAuth2/Token/Access.php * @package OAuth2 * @category Token * @author Phil Sturgeon * @copyright (c) 2011 HappyNinjas Ltd */ class Token_Access extends Token implements