How can I store a class object with a dictionary into neo4j? - neo4jclient

I need to have a dictionary in class.
Now I want to save the class object into neo4j by neo4jclient(i'm using c#)
But it seems something wrong.
I always get the error "MatchError: Map() (of class scala.collection.convert.Wrappers$JMapWrapper"
Can anyone help?

Related

Create an instance of a class inside its own self

Here's the situation.
I have a swift model class file that contains all the variables for a weather forecast (min temperature, max temperature, humidity, etc).
The class also contains the function that downloads all the data from the API.
My question is, is it possible to create an array of the class inside the class itself, so that I can append a number of objects (of the same class itself) based on the number of days of forecast the API sends back?
If so, can you tell me how it could be achieved?
The other option I have that totally works, is to do the API downloading and parsing outside of the forecast class (in the ViewController) but that would make my ViewController messy.
You shouldn't call the API to get all the weather's datas in your model but in a dedicated class.
Also, you shouldn't parse and store the datas inside your model.
In your model, you only need to have all the attributes of your object and methods.
Maybe you can create an Helper class where you implements all this methods and store the datas.
There's nothing preventing you from referencing a class name within its definition. So you can do something like this:
class Foo {
var boz = [Foo]() // you can append to this array as needed
}

How to use inheritance with Swift and ObjectMapper?

I'm new to Swift and I have to serialize an object structure into a JSON string in my iOS( iOS >= 8) project.
So I decided to use the ObjectMapper library (I integrated it with Cocoapod).
But my problem is that the structure is the following.
ObjectA can have a list of children objects as an array stored in an instance variable.
Objects that can be stored in the instance array can be of multiple types, say ObjectB and ObjectC. So, in Java with GSON I would have created an InterfaceD and made both of my classes implement it and made the array in ObjectA store InterfaceD types, but I can't figure how to do this with Swift object model as it results in empty {} JSON objects.
The resulting JSON should look like this.
{"children":[
{"type":"ObjectB", "value1":"foo"},
{"type":"ObjectC", "value1":"bar", "value2":"baz"}
]}
and I get
{"children":[
{},
{}
]}
Notice that the two entries that have to be serialized from objectA and ObjectC should have different structures.
I tried multiple things but each times I'm stuck in a dead end.
I tried using generics, tried to use Mappable protocol as my array type, I tried classic class inheritence but any one failed.
Have you any idea how I can achieve this ?
Note that I know that I could add a serialization function to each object and retrieve the strings recursively and concatenate them. But I really want to avoid implementing a JSON serializer by myself as I already use on successfully as Alamofire is already used in the project). Also implementing a new serializer is error prone and not a clean way to solve the problem IMO.
Thanks a lot.
I never had the solution but as a workaround I just made my objects produce a dictionnary from all its values. Then I recursively add child objects dictionnaries as the current dictionnary values.
It adds a toDict() function to each object that I forced with a protocol.
When the resulting object is only made of a tree of dictionnaries, the ObjectMapper serialization works fine...

Map RLMObject from array and not dictionary with Realm-JSON

I have a data structure that looks like following:
I'm trying to map it. I will have array of DayChoice objects.
Each of them contains index and string properties.
Now I face trouble with writing mapping, usually it goes like this:
But as you can see my DayChoice objects do not have keys, and are in arrays. How do I write mapping for this?
For anyone finding this, this seems to have been resolved in Realm-JSON #88.

This is a generic design pattern regarding accessing model object value

In iOS, I have three controllers A,B,C. I have a model object and I am storing text box value in model property of an object and then I am storing model object in database where all this things happening in controller A. In controller C, I am trying to access that model object property, it shows me nil. I don't know why. Below is the example:
I have a model.m class like below
#implementation model:NSObject
#property(nonatomic)NSString *firstname;
A.m class
model m=[model alloc]init];
m.firstname=#"stackoverflow";
// and saving the "m" in PARSE framework which internally stores in database.
C.m class
model m =[model alloc]init];
NSLog(#"%#",m.firstname);// shows null value
what is the right way to access it? Please help me in this case.
You should use a Single Instance

Dynamic cast error in swift

Currently I am trying to loop through NSArray which contains NSManagedObject.
When I am trying to cast the fetched object its throwing me an error.
Here is the code
for var i = 0; i < self.displayedHistoryListContent.count ; i=i+1{
var productObject: Product = self.displayedHistoryListContent.objectAtIndex(i) as Product
}
Product is my NSManagedObject.
Application crashes at the line where I am doing casting 'as Product'
Can someone tell me where I am going wrong?
Are you sure that the objects in the array are in fact of the class Product? When dealing with NSManagedObject's it is easy to get confused and refer to a set instead of the object itself.
You probably know that a cast is not a conversion?
Use a println() to see wat kind of object is really in there
It really looks like your array does not contain Products only. Try with as? instead of as to confirm this. You can use NSLog to see what is in the array when you expect a Product.

Resources