serialization

Inject Service into custom Jackson Serializer

我只是一个虾纸丫 提交于 2020-03-06 03:06:27
问题 Hi I have problem in the following scenario: I'm using Spring 4.xx with Jackson 2.xx and I'm ompelenting a RESTful Web Application. I'm now faced with te problem that I need some custom serialzation for one of my models, so i used a custom serilaizer, but i also need to fetch some data out of the database while serializing. So I tried to inject my Serivce into the Serializer but it always stays null. As far as I have read this happens if you instanciate your object directly, which I guess is

How to implement Boost::Serialize for Boost::Nested_Container

匆匆过客 提交于 2020-03-05 06:04:29
问题 (Followup of another question.) Boost::Serialize often delivers an exception on oarchive, complaining that re-creating a particular object would result in duplicate objects. Some archives save and re-load successfully, but many result in the error above. I have not been able yet to determine the exact conditions under which the error occurs, but I have proven that none of the content used to populate the nested_container and the flat object list contains duplicate object IDs. I am using text

how to serialize list of form object to JSON in django

ε祈祈猫儿з 提交于 2020-03-05 00:28:17
问题 I'm trying to serialize the form objects and return to the AJAX call so that I can display them in the template, but I'm not able to serialize them unlike serializing the model objects don't we have an option for form objects if request.method == 'POST': temp_data_form = TemplateDataForm(request.POST) if request.POST.get('temp_id'): # getting id of the current template existing_template = Template.objects.filter(id=request.POST.get('temp_id'))[0] if request.POST.get('item'): item_query =

How to work around Gson serialization giving different results when using generic wildcards?

眉间皱痕 提交于 2020-03-03 12:37:31
问题 Consider this example: static class BaseBean { String baseField = "base"; } static class ChildBean extends BaseBean { String childField = "child"; } static class BaseBeanHolder { List <? extends BaseBean> beans; public BaseBeanHolder(List<? extends BaseBean> beans) { this.beans = beans; } } static class ChildBeanHolder { List <ChildBean> beans; public ChildBeanHolder(List<ChildBean> beans) { this.beans = beans; } } @Test public void mcve() { BaseBeanHolder baseHolder = new BaseBeanHolder

How to work around Gson serialization giving different results when using generic wildcards?

天大地大妈咪最大 提交于 2020-03-03 12:37:19
问题 Consider this example: static class BaseBean { String baseField = "base"; } static class ChildBean extends BaseBean { String childField = "child"; } static class BaseBeanHolder { List <? extends BaseBean> beans; public BaseBeanHolder(List<? extends BaseBean> beans) { this.beans = beans; } } static class ChildBeanHolder { List <ChildBean> beans; public ChildBeanHolder(List<ChildBean> beans) { this.beans = beans; } } @Test public void mcve() { BaseBeanHolder baseHolder = new BaseBeanHolder

What causes ClassCastException when serializing TypeTags?

ε祈祈猫儿з 提交于 2020-03-03 04:46:26
问题 Situation I'm serializing an implementation of this class: abstract class FnDescriptor[T <: FnRequest: TypeTag, R <: FnResponse: TypeTag] with Serializable { override type Input = T override type Output = R override type State = S val inputTag: TypeTag[Input] = implicitly[TypeTag[T]] val outputTag: TypeTag[Output] = implicitly[TypeTag[R]] } and sending it over REST to a Gateway, which reads it to find the types of input and output state. (Yes I know this isn't a great design) Results Now if I

How to append object to a file while serializing using c# protobuf-net?

試著忘記壹切 提交于 2020-03-02 06:57:12
问题 I got a source code of Protobuf-net that serializes an object to a file. var person = new Person { Id = 12345, Name = "Fred", Address = new Address { Line1 = "Flat 1", Line2 = "The Meadows" } }; using (var file = File.Create("person.bin")) { ProtoBuf.Serializer.Serialize(file, person); } But suppose i have two instance of Person that i want to serialize into a single file. how can i do that? 回答1: protobuf, in the pure sense, does not have any "terminator" except the end of a file (this is so

Serialize fixed size Map to CBOR

荒凉一梦 提交于 2020-03-01 06:43:18
问题 I have the following JSON: [ { 2: { "c": true } }, { 3: { "p": 10 } } ] That I would like to convert to CBOR format. Accordingly to cbor.me I have the following output: 82A102A16163F5A103A161700A But, when using Jackson Binary CBOR Serializer, I have the following output: 82BF02BF6163F5FFFFBF03BF61700AFFFF Which is not wrong, but not optimized... I have an extra 4 unnecessary bytes added to what it can really be. I've then tried to manually serialize the JSON but same result: @Override public

Jackson deserialize JSON with timestamp field

旧巷老猫 提交于 2020-02-29 11:35:10
问题 I have such string: { "debug":"false", "switchTime":"2017-04-12 17:04:42.896026" } I'm trying to get object in such approach: new ObjectMapper().readValue(string, MyObject.class); And MyObject class: class MyObject { private Boolean debug; private Timestamp switchTime; //...getters, setters, constructors } I have such exception: com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type java.sql.Timestamp from String "2017-04-12 17:04:42.896026": not a valid

Jackson deserialize JSON with timestamp field

我只是一个虾纸丫 提交于 2020-02-29 11:33:50
问题 I have such string: { "debug":"false", "switchTime":"2017-04-12 17:04:42.896026" } I'm trying to get object in such approach: new ObjectMapper().readValue(string, MyObject.class); And MyObject class: class MyObject { private Boolean debug; private Timestamp switchTime; //...getters, setters, constructors } I have such exception: com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type java.sql.Timestamp from String "2017-04-12 17:04:42.896026": not a valid