serializer

Spring : FasterXML cannot access a member of class with modifiers private

僤鯓⒐⒋嵵緔 提交于 2019-12-07 20:22:23
问题 I am getting an unknown error from somewhere and it all started today. I have no idea what is going wrong. I cannot find many posts who have this problem. I am posting my error log and my configuration. Can anyone tell me what is wrong. Thanks. Error log : Sep 08, 2015 2:21:47 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [appServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang

Jackson - combine @JsonValue and @JsonSerialize

蹲街弑〆低调 提交于 2019-12-07 13:44:44
问题 I am trying a combination of @JsonValue and @JsonSerialize . Let's start with my current container class: public class Container { private final Map<SomeKey, Object> data; @JsonValue @JsonSerialize(keyUsing = SomeKeySerializer.class) public Map<SomeKey, Object> data() { return data; } } In this case, the custom serializer SomeKeySerializer is not used. If I change the container as following, the serializer is called: public class Container { @JsonSerialize(keyUsing = SomeKeySerializer.class)

Spring : FasterXML cannot access a member of class with modifiers private

筅森魡賤 提交于 2019-12-06 06:21:10
I am getting an unknown error from somewhere and it all started today. I have no idea what is going wrong. I cannot find many posts who have this problem. I am posting my error log and my configuration. Can anyone tell me what is wrong. Thanks. Error log : Sep 08, 2015 2:21:47 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [appServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Failed to instantiate standard serializer (of type com.fasterxml.jackson.databind.ser.std

Use the “circular_reference_handler” key of the context instead symfony 4.2

北战南征 提交于 2019-12-06 05:02:28
I have to serialize an object and I get the ever so common "circular reference error" I have used the old Symfony method : $normalizer = new ObjectNormalizer(); // Add Circular reference handler $normalizer->setCircularReferenceHandler(function ($object) { return $object->getId(); }); $normalizers = array($normalizer); $encoders = [new JsonEncoder()]; $serializer = new Serializer($normalizers, $encoders); This work but as of Symfony 4.2 I get the exception you see in the title of this question : use the "circular_reference_handler" key of the context instead Symfony 4.2 I cannot find any

Serializing an IEnumerable trough WCF using Protobuf-net and Monotouch for IOS

佐手、 提交于 2019-12-05 07:23:45
I'm trying to code a WCF service on Monotouch/Monodevelop for IOS. I was using standard attributes like [DataMember]/[DataContract] for my serializable object and [ServiceContract]/[OperationContract] for my interface. Everything worked fine, but when I tried to implement a method returning an IEnumerable on the interface implementation (server side), it didn't worked. So to solve my problem I tried to use the latest version of protobuf-net being protobuf-net v2 beta r404. But I'm still getting a serialization error from Protobuf-net. Note that the IEnumerable in "MyObject" serialize without

Upload File using Django Rest Framework

前提是你 提交于 2019-12-04 12:20:03
问题 I am new to django. Can anybody help me... How can I upload a file using the Rest Framework API ? I have tried following this page: http://www.django-rest-framework.org/api-guide/parsers/#fileuploadparser 回答1: File uploading in Django REST framework is the same with uploading files in multipart/form in django. To test it you can use curl: curl -X POST -H "Content-Type:multipart/form-data" -u {username}:{password} \ -F "{field_name}=@{filename};type=image/jpeg" http://{your api endpoint} Other

XMLSerializer to XElement

…衆ロ難τιáo~ 提交于 2019-12-04 10:17:03
问题 I have been working with XML in database LINQ and find that it is very difficult to work with the serializer. The database LINQ required a field that store XElement . I have a complex object with many customized structure class, so I would like to use the XmlSerializer to serialize the object. However, the serializer can only serialize to file ("C:\xxx\xxx.xml") or a memory stream. However to convert or serialize it to be a XElement so that I can store in the database using LINQ? And How to

Django REST Framework ValidationError always returns 400

吃可爱长大的小学妹 提交于 2019-12-04 02:36:42
问题 I am trying to force ValidationError to return a different status code than 400. This is what I did: class MyValidationError(ValidationError): status_code = HTTP_403_FORBIDDEN and then in a serializer: def validate_field(self, value): raise MyValidationError Why do I get 400 here instead of 403? An interesting thing is that if I use PermissionDenied with a custom status code (I tried 204) instead of ValidationError , it works as expected. 回答1: The Django RestFramework serializer validates all

C# DataContractJsonSerializer fails when value can be an array or a single item

拟墨画扇 提交于 2019-12-03 17:03:02
I use the DataContractJsonSerializer to parse a json string into a object hierarchie. The json string looks like this: { "groups": [ { "attributes": [ { "sortOrder": "1", "value": "A" }, { "sortOrder": "2", "value": "B" } ] }, { "attributes": { "sortOrder": "1", "value": "C" } } ] } As you can see the sub value of "attributes" can be an array or a single item. I found the code part where the problem occures: [DataContract] public class ItemGroup { [DataMember(Name="attributes")] public List<DetailItem> Items { get; set; } } This works for the first one but fails on the second one. Has anyone

django rest framework: set field-level error from serializer validate() method

烂漫一生 提交于 2019-12-03 09:04:51
问题 I have a serializer that validates fields based on the values of other fields, In the error response I would like to show each field error as a field error as opposed to showing everything under "non_field_errors" which is what would happen if I were to raise a ValidationError in the object-level validate method. Below is an illustration of what I'm trying to achieve: MySerializer(ModelSerializer): ... def validate(self, data): field_val1 = data['field_val1'] field_val2 = data['field_val2']