Git Product home page Git Product logo

uacaps / nsobject-objectmap Goto Github PK

View Code? Open in Web Editor NEW
434.0 434.0 52.0 1.45 MB

This is a drop-in category of NSObject that makes it easy to initialize custom objects from JSON or XML (SOAP included), and to serialize those objects back into JSON/XML. It only requires a little bit of set-up - and then you never have to fuss with creating your own serialization and initialization methods for each custom NSObject ever again.

License: BSD 3-Clause "New" or "Revised" License

Objective-C 99.53% Ruby 0.36% Shell 0.11%

nsobject-objectmap's People

Contributors

adfleshner avatar bennyguitar avatar ibru avatar kevinhong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nsobject-objectmap's Issues

JSON-Boolean <---> Objective-C BOOL

I use a JSON API with boolean properties.
For example:
{
     "is_used": false,
     "is_unique": true
}

This allows your class to deal only during deserialization, but not in the serialization. What would be a good way to solve this?

Crash because of NULL properties and nil objects

Til know, I've faced two issues
First, if a key exists in the JSON dictionary and not exist in the NSObject it'll cause an expcetion.
The fix:
in NSObject+ObjectMap.m from line 391 to line 402 replace them with (put them inside if condition that checks if the property is not null)

if(property != NULL){
                                NSString *classType = [self typeFromProperty:property];
                                // check if NSDate or not
                                if ([classType isEqualToString:@"T@\"NSDate\""]) {
                                    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                                    [formatter setDateFormat:OMDateFormat];
                                    [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]];
                                    NSString *dateString = [[nestedArray[xx] objectForKey:newKey] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
                                    [nestedObj setValue:[formatter dateFromString:dateString] forKey:newKey];
                                }
                                else {
                                    [nestedObj setValue:[nestedArray[xx] objectForKey:newKey] forKey:newKey];
                                }
                            }

The second issue is in the same file line 411 before adding the object to the array, make sure it's not a nil object.

Doubt

Hi friend

How to pass the url and parameter. New developer for SOAP can u explain me.

Wsdl : http://82.178.20.92:8080/CRM2/services/SearchBusiness.ws?wsdl
function : getSearchBusiness
Parameters : array( 'businessCode' => '{"businessCode":[]}',
'businessName' => '@""',
'location' => @"",
'categoryKeyword' => @"",
PageNumber' => 1,
'paginationSize' => 10,
'languageCode' => en''
)

Double Alloc

In our main methods (initWithData:type: and their JSON/XML/SOAP equivalents), we're basically double alloc-ing, and I'm not sure if this has any negative effects. Does ARC take care of this? I know it can't be great practice, and we're working on refactoring things to make JSON/XML/SOAP -> Objects make the most sense from a semantic/conceptual standpoint.

Does anyone have thoughts on this?

Subclassing - Init infinite loop

How does subclassing work using the initWithJSONData constructor?
Given the following class constructor (invoked only once):


- (id)init {
    NSData* raw = [NSData dataWithContentsOfFile:
                   [[NSBundle mainBundle] pathForResource:@"user" ofType:@"json"]];
    if (self = [MCUser initWithJSONData:raw]) {

    }
    return self;
}

Replacing MCUser initWith.. with self or super also brings the same result.

The app enters an infinite loop (EXC_BAD_ACCESS).
Any idea how use it properly?

Complex JSon not able to convert to class object

Hi,
I have complex Json data. And when I am trying to convert to custom class it is returning nil.
Below is the example of JSon data.
{
"FiltersCount":{
"isFemale":[
{"Id":"T","Count":1310},
{"Id":"F","Count":146},
{"Id":"all_count","Count":1456}]
}
}

I am using Swift and trying to convert to below class's object.
========START=========
import Foundation
class ResultFilterCount : NSObject{
var FiltersCount : FiltersKeyValue?
override init(){
super.init()
if(self != nil){
self.setValue("FiltersKeyValue", forKeyPath: "propertyArrayMap.FiltersCount")
}
}
}

class FiltersKeyValue: NSObject{
var isFemale: [FilterResultModel]?
override init(){
super.init()
self.setValue("FilterResultModel", forKeyPath: "propertyArrayMap.isFemale")
}
}

class FilterResultModel: NSObject{
var Id : NSString?
var Count: NSNumber?
override init(){
super.init()
self.setValue("NSString", forKeyPath: "propertyArrayMap.Id")
self.setValue("NSNumber", forKeyPath: "propertyArrayMap.Count")
}
}

========END=========

This is the code to convert to class.
var data = results as NSData
var pList = ResultFilterCount(JSONData: data)

Result: It returns nil.
Expected Result : It should return ResultFilterCount object with different properties and values.

thanks
ankur

null node get value error

hi: i found a bug
such as this xml:PEK


AM

at last the CONTINENTCN node value is[AM] how can solve?

2013-11-14 11 04 08

Specific mapping from JSON to NSObject property

Automatic mapping is cool, but sometimes you just don't want to use the same names from the JSON for your object properties.
Could you be interested in this feature? If yes, I will take care of implementing it in my spare time. I was thinking of something like creating a protocol and asking the object for a mapping between JSON fields and its properties. If you don't implement the protocol, everything will work as now, otherwise you can customize things a little bit more.
I was also thinking on creating another protocol for parsing and trasforming (or normalize) the values from JSON (or XML) before setting the properties, but this could be an issue on its own.
Let me know what you think!
Thanks

Handling the attributes in xml

Now there is no manipulation for attributes they are simply ignored. Adding this will completely avoid the effort of xml parsing.
It should be better to map the attributes inside a tag to the same named properties within the object as in case of elements do
for eg : Need to handle the tag
screen shot 2014-01-07 at 10 21 24 am

Suddenly stopped working for a simple nested object

Hi,

I am using this library for the last 4 years. Now suddenly it's not working for a simple object. I'm using an Apple M1 mac could this be an issue? I have response like this

"dateTime": "26-Apr-2022 9:00:06 AM",
            "postType": "FRIEND",
            "postCreationTimestamp": 1650963267,
            "linkPreview": null,
            "videoStreaming": {
                "channelName": "CDC6423B-331C-4E21-AA21-A45C8D36CFA8"
            },

And this is my Data Model properties. I have not added all properties here.

@Property (nonatomic,strong) NSNumber* postCreationTimestamp;
//Added For Live Video Streaming
@Property (nonatomic,strong) DNLiveStreamingChannel* videoStreaming;

The issue I'm getting is videoStreaming is always getting nil even if it's available in response. However other objects are getting parsed properly. How do I fix this issue?

UPDATE - When I debugged it I found that it's type is always NSNULL instead of class Type

Help creating my custom object class

Hello, I am looking a way to deserialize a xml response. This is the xml that I receipt:
 
xml

And what I need is the token property in this case. I don´t understand how is the structure of the class I have to create, always get a null log... Any help please?

Self closing tag with spaces.

I have a node called <StatusMessage /> but it seems to cause issues with the rest of the properties not being filled out.

I think it's the space between StatusMessage and the />

How to fetch Soap String

I have used [[Class alloc]initWithSOAPData:operation.responseData]; . When I tried to fetch Soap String app crashed with this error '-[Class Header]: unrecognized selector sent to instance .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.