object-graph

How Can I Convert Nested YAML to nested Arrays and OpenStructs in Ruby

拥有回忆 提交于 2020-01-05 09:48:48
问题 How should I convert a series of nested hashes (nested to arbitrary depth) to a series of nested OpenStructs? I'm loading in a big YAML file and I'm not enjoying accessing['everything']['like']['this'] . I have found a few partial solutions using Google, but I thought this would make a nice question here. Here is one of the solutions I found from http://andreapavoni.com/blog/2013/4/create-recursive-openstruct-from-a-ruby-hash: # deep_struct.rb require 'ostruct' class DeepStruct < OpenStruct

How Can I Convert Nested YAML to nested Arrays and OpenStructs in Ruby

拈花ヽ惹草 提交于 2020-01-05 09:46:09
问题 How should I convert a series of nested hashes (nested to arbitrary depth) to a series of nested OpenStructs? I'm loading in a big YAML file and I'm not enjoying accessing['everything']['like']['this'] . I have found a few partial solutions using Google, but I thought this would make a nice question here. Here is one of the solutions I found from http://andreapavoni.com/blog/2013/4/create-recursive-openstruct-from-a-ruby-hash: # deep_struct.rb require 'ostruct' class DeepStruct < OpenStruct

Rails 3: Escape characters (\) appearing in part of JSON string

风格不统一 提交于 2020-01-04 02:30:55
问题 Anyone know why some of my json elements are being backslash( \ ) escaped while others are not? {"first":"John","last":"Smith","dogs":"[{\"name\":\"Rex\",\"breed\":\"Lab\"},{\"name\":\"Spot\",\"breed\":\"Dalmation\"},{\"name\":\"Fido\",\"breed\":\"Terrier\"}]"} Ideally I'd like NONE of them to be escaped... This was generated by overriding as_json in two models. Person has_many Dogs. #models/person.rb class Person < ActiveRecord::Base has_many :dogs def as_json(options={}) { :first => first,

Ignore internal properties in ShouldBeEquivalentTo

佐手、 提交于 2019-12-23 19:11:17
问题 Is there a way to ignore internal properties of a class when doing ShouldBeEquivalentTo? For example, in the class below I want to exclude the MetaData property from the object graph comparison. public class SomeObject { Public string SomeString { get; set; } internal MetaData MetaData { get; set; } } I would prefer to not use someObject.ShouldBeEquivalentTo(someOtherObject, options => options.Excluding(info => info.SelectedMemberPath == "MetaData") Because I might have more than 1 internal

Clone Whole Object Graph

只谈情不闲聊 提交于 2019-12-18 11:44:42
问题 While using this code to serialize an object: public object Clone() { var serializer = new DataContractSerializer(GetType()); using (var ms = new System.IO.MemoryStream()) { serializer.WriteObject(ms, this); ms.Position = 0; return serializer.ReadObject(ms); } } I have noticed that it doesn't copy the relationships. Is there any way to make this happen? 回答1: Simply use the constructor overload that accepts preserveObjectReferences , and set it to true: using System; using System.Runtime

JSON.NET CustomCreationConverter with nested objects

穿精又带淫゛_ 提交于 2019-12-10 15:08:53
问题 that is my very first question I ask on this site, so forgive me if I missed something. I have some problems deserializing an complex object graph using JSON.NET. My class hierarchy is (simplified) as follows: public abstract class BusinessObjectBase { protected BusinessObjectBase(SerializationContext context) { } } public class TestBusinessObject : BusinessObjectBase { protected TestBusinessObject(SerializationContext context) : base(context) { } public NestedObject InnerObject { get; set; }

Java Serialization of referenced objects is “losing values”?

回眸只為那壹抹淺笑 提交于 2019-12-10 10:57:57
问题 Good day, I am having an interesting problem that I cannot understand. I have a class called "HomeScreenManager" which maintains a LinkedList<String> called chat . The HomeScreenManager instance lives on the server and is in charge of keeping track of the connections and the chat log. I then created a class called "ProtocolHomeScreen" which is a class with a LinkedList<String> called chat and implements Serializable. When it comes time to update all the clients with the chat, I want to send

Can I create a Core Data object graph in one application, then use it in another from a preset state?

淺唱寂寞╮ 提交于 2019-12-08 02:09:50
问题 My app as it stands now has a .plist of around 5,000 dictionaries which, at runtime, I use to create 5,000 objects of my custom class. Each one contains a few strings, some boolean values, etc. This is a fairly quick process, takes a few seconds, tops, but it's a bit unwieldy using a .plist with thousands of objects. I'm going to migrate to Core Data (which I've never used before), so the initial step is going to be getting the data from that .plist into those custom objects, then saving them

Java Serialization of referenced objects is “losing values”?

巧了我就是萌 提交于 2019-12-06 07:26:50
Good day, I am having an interesting problem that I cannot understand. I have a class called "HomeScreenManager" which maintains a LinkedList<String> called chat . The HomeScreenManager instance lives on the server and is in charge of keeping track of the connections and the chat log. I then created a class called "ProtocolHomeScreen" which is a class with a LinkedList<String> called chat and implements Serializable. When it comes time to update all the clients with the chat, I want to send out a ProtocolHomeScreen. So I create a brand new instance of the ProtocolHomeScreen and I say that it's

Can I create a Core Data object graph in one application, then use it in another from a preset state?

我的梦境 提交于 2019-12-06 06:32:22
My app as it stands now has a .plist of around 5,000 dictionaries which, at runtime, I use to create 5,000 objects of my custom class. Each one contains a few strings, some boolean values, etc. This is a fairly quick process, takes a few seconds, tops, but it's a bit unwieldy using a .plist with thousands of objects. I'm going to migrate to Core Data (which I've never used before), so the initial step is going to be getting the data from that .plist into those custom objects, then saving them in the context. I've watched the videos and such, and think I'm going to be okay doing that. My first