deserialization

GSON: JSON deserialization to variable type (List/String)

爱⌒轻易说出口 提交于 2019-12-18 07:15:11
问题 At this point it's already an old question and I've probably read every related topic on SO. But to the point. I need some advice or correction maybe? For some reason we have generatable Jsons of 2 types: {"data": {"id": "value"}} and {"data":[{"id": "value"}]} Object and Array. There are also other params but they doesn't matter here. "id" is differ for every request. Sometimes it's userId, portfolioId etc. So I get "id" and pass it to related var. For a long time I was working with the

GSON: JSON deserialization to variable type (List/String)

空扰寡人 提交于 2019-12-18 07:15:10
问题 At this point it's already an old question and I've probably read every related topic on SO. But to the point. I need some advice or correction maybe? For some reason we have generatable Jsons of 2 types: {"data": {"id": "value"}} and {"data":[{"id": "value"}]} Object and Array. There are also other params but they doesn't matter here. "id" is differ for every request. Sometimes it's userId, portfolioId etc. So I get "id" and pass it to related var. For a long time I was working with the

Assembly Independent Serialization in .NET

断了今生、忘了曾经 提交于 2019-12-18 05:54:18
问题 I use Serialization/DeSerialization Technique. BinaryFormatter class. Each time when new assembly is created the BinaryFormatter can't Deserialize binary data even if the class structure is the same, but the Assembly version differs. Is it possible to Deserialize binary buffer with no checking the assembly version if the class structure stays unchanged? 回答1: Try this: public sealed class CurrentAssemblyDeserializationBinder : SerializationBinder { public override Type BindToType(string

Using JavaScript to deserialize references in a complex object graph from SignalR/Json.NET

自古美人都是妖i 提交于 2019-12-18 05:43:11
问题 I'm using SignalR to return a complex object graph to my JavaScript client. This object graph has multiple references throughout to the same object, so the JSON that SignalR/Json.NET returns looks a lot like this: { "$id": "57", "Name": "_default", "User": { "$id": "58", "UserTag": "ken", "Sessions": [{ "$id": "59", "SessionId": "0ca7474e-273c-4eb2-a0c1-1eba2f1a711c", "User": { "$ref": "58" }, "Room": { "$ref": "57" } }], }, "Sessions": [{ "$ref": "59" }] } (Of course, a lot more complicated

Can't deserialize with binaryFormatter after changing namespace of class [duplicate]

こ雲淡風輕ζ 提交于 2019-12-18 04:47:07
问题 This question already has answers here : duplicated id with fragment (3 answers) Is it possible to recover an object serialized via “BinaryFormatter” after changing class names? (1 answer) Closed 5 years ago . After changing the namespace of my class I can no longer deserialize the objects. I've implemented SerializationBinder . Example: public class TypeNameConverter : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { typeName = typeName.Replace(

Jackson Dynamic filtering of properties during deserialization

大憨熊 提交于 2019-12-18 04:45:12
问题 I have a REST WS to update a bean object which receives a JSON string as input. ABean entity = svc.findEntity(...); objectMapper.readerForUpdating(entity).readValue(json); [...] svc.save(entity); ABean is a complex type containing also other objects e.g.: class ABean { public BBean b; public CBean c; public String d; } svc.save(...) will save the bean and the embedded objects . For security reasons I want to filter out some of the properties that can be updated by the JSON string, but I want

Although the Serializable interface in Java has no methods, no fields, it can achieve its function. How?

て烟熏妆下的殇ゞ 提交于 2019-12-18 04:36:11
问题 Although the java.io.Serializable interface public interface Serializable{} surprisingly doesn't contain any methods and fields in Java, the class that implements this interface is able to achieve the function of serialization and deserialization (the state of the object being serialized or deserialized). How can it achieve the function of serialization and deserialization without any methods or fields in Java? 回答1: Some interfaces serve only as "markers" or "flags". The UID and custom

Deserializing JSON object into a C# list

你。 提交于 2019-12-18 04:14:40
问题 I'm trying to deserialize a given JSON file in C# using a tutorial by Bill Reiss. For XML data in a non-list this method works pretty well, though I would like to deserialize a JSON file with the following structure: public class Data { public string Att1 { get; set; } public string Att2 { get; set; } public string Att3 { get; set; } public string Att4 { get; set; } } public class RootObject { public List<Data> Listname { get; set; } } My problem is with using JSON.Net's ability to create /

Deserialize an entity with a relationship with Symfony Serializer Component

回眸只為那壹抹淺笑 提交于 2019-12-18 03:23:27
问题 I'm trying to deserialize an entity with a relationship using the symfony serializer component. This is my entity: namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Document * * @ORM\Table(name="document") * @ORM\Entity(repositoryClass="AppBundle\Repository\DocumentRepository") */ class Document { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\ManyToOne(targetEntity="Genre", inversedBy=

Capture exception during request deserialization in WebAPI C#

只愿长相守 提交于 2019-12-18 03:10:15
问题 I'm using WebAPI v2.2 and I am getting WebAPI to deserialise JSON onto an object using [FromBody] attribute. The target class of the deserialisation has a [OnDeserialized] attribute on an internal method, like this: [OnDeserialized] internal void OnDeserialisedMethod(StreamingContext context) { // my method code } I know for a fact there is a problem with the code inside this method, I've stepped through it and found it. The problem for me is that I get no exception at all. What happens is