serialization

How do I unit test a Grails service that uses a converter?

陌路散爱 提交于 2020-06-09 10:59:46
问题 I have a Grails service that sends out e-mails using a 3rd-party service by doing a HTTP call: class EmailService { def sendEmail(values) { def valueJson = values as JSON ... // does HTTP call to 3rd party service } } I've written a unit test to test this service (because an integration test spins up Hibernate and the entire domain framework, which I don't need): @TestFor(EmailService) class EmailServiceTests { void testEmailServiceWorks() { def values = [test: 'test', test2: 'test2'] service

saving and loading objects from file using jsonpickle

橙三吉。 提交于 2020-06-09 09:34:48
问题 I have the following simple methods for writing a python object to a file using jsonpickle: def json_serialize(obj, filename, use_jsonpickle=True): f = open(filename, 'w') if use_jsonpickle: import jsonpickle json_obj = jsonpickle.encode(obj) f.write(json_obj) else: simplejson.dump(obj, f) f.close() def json_load_file(filename, use_jsonpickle=True): f = open(filename) if use_jsonpickle: import jsonpickle json_str = f.read() obj = jsonpickle.decode(json_str) else: obj = simplejson.load(f)

Java StreamCorruptedException

吃可爱长大的小学妹 提交于 2020-06-09 05:19:09
问题 I have a client and server application that transfer message using serialization over TCP. I got the following error when deserializing an object: Any ideas to the cause or possible next steps in analyzing this problem? java.io.StreamCorruptedException: invalid stream header: 383D4649 at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at java.io.ObjectInputStream.<init>(Unknown Source) at com.aqua.NmsApi.ResiliantTCPServer$ServerThread.run(ResiliantTCPServer.java:248) at java.lang

How can I convert between a double-double and a decimal string?

只谈情不闲聊 提交于 2020-06-08 19:44:06
问题 One way of increasing precision beyond that of a double (e.g. if my application is doing something space-related that needs to represent accurate positions over distances of many light-years) is to use a double-double, a structure composed of two doubles which represents the sum of the two. Algorithms are known for the various arithmetic operations on such a structure, e.g. double-double + double-double, double × double-double, etc, e.g. as given in this paper. (Note that this is not the same

Type mismatch in django serializer for request parsing

前提是你 提交于 2020-06-01 07:05:56
问题 I had created the following serializers for request parsing of JSON data. However, while performing the operation, I get an unexpected error. class A(serializers.ModelSerializer): class Meta: model = CName fields = ('id','contact','email') read_only_fields=('contact',) class B(serializers.ModelSerializer): class Meta: model = PName fields = ('id','contact','number') read_only_fields=('contact',) class C(serializers.ModelSerializer): contact_number = A(many=True) contact_email = B(many=True)

Type mismatch in django serializer for request parsing

依然范特西╮ 提交于 2020-06-01 07:03:59
问题 I had created the following serializers for request parsing of JSON data. However, while performing the operation, I get an unexpected error. class A(serializers.ModelSerializer): class Meta: model = CName fields = ('id','contact','email') read_only_fields=('contact',) class B(serializers.ModelSerializer): class Meta: model = PName fields = ('id','contact','number') read_only_fields=('contact',) class C(serializers.ModelSerializer): contact_number = A(many=True) contact_email = B(many=True)

Type mismatch in django serializer for request parsing

白昼怎懂夜的黑 提交于 2020-06-01 07:03:24
问题 I had created the following serializers for request parsing of JSON data. However, while performing the operation, I get an unexpected error. class A(serializers.ModelSerializer): class Meta: model = CName fields = ('id','contact','email') read_only_fields=('contact',) class B(serializers.ModelSerializer): class Meta: model = PName fields = ('id','contact','number') read_only_fields=('contact',) class C(serializers.ModelSerializer): contact_number = A(many=True) contact_email = B(many=True)

How to affect timezone when serializing DateTimeOffset with System.Text.Json?

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-01 06:52:06
问题 Task to solve: Given a DateTimeOffset , its value has a particular Offset. I would like to serialize it with the exact form as it was represented, with that exact date and time value and exact same Offset value Problem Currently when serializing the moment is correct, but the formatted serialized version of the point in time is converted to the offset which is according to the current timezone. (This way although the point in time remains correct, but the original offset information lost)

Json.NET: How to make DefaultValueHandling only apply to certain types?

旧时模样 提交于 2020-05-31 07:27:07
问题 I have a custom class that looks like this: public class PartnerLoginOptions { public string Username { get; set; } public string Password { get; set; } public string DeviceModel { get; set; } public string Version { get; set; } public bool? IncludeUrls { get; set; } public bool? ReturnDeviceType { get; set; } public bool? ReturnUpdatePromptVersions { get; set; } } I'd like to ignore any bool? members with default values when serializing, but keep strings with null values. For example, if I

Layout NLog properties as JSON?

五迷三道 提交于 2020-05-27 05:49:45
问题 I am trying to figure out how to log all the properties in a LogEventInfo object to a JSON-formatted string. Per the issue on github, I tried to do something like this: <target xsi:type="ColoredConsole" name="coloredConsole"> <layout xsi:type="JsonLayout"> <attribute name="timestamp" layout="${longdate}"/> <attribute name="level" layout="${level:uppercase=true}"/> <attribute name="exception" layout="${onexception:${exception:format=tostring}}" /> <attribute name="properties" encode="false">