Giter Site home page Giter Site logo

Comments (2)

kprevas avatar kprevas commented on August 18, 2024

You're right, we don't go more than one level deep. I can look in to this.

from ronin.

1cg avatar 1cg commented on August 18, 2024

It'd be nice if you could either/or it: either embed an ID in the "fromID" attribute or, if that isn't present, then new up the object and reflect.

Here is the code that I sent to the interns, which appears to kind of work:

function deserializeJSON( str : String, rootType : Type ) : T {

var x = new JSONReader()

var root = x.read( str )

return transformObj( root, rootType ) as T

}

function transformObj( val : Object, type : Type ) : Object {

if( val typeis Map ) {

var instance = type.TypeInfo.getConstructor( {} ).Constructor.newInstance( {} )

val.eachKeyAndValue( \ propName, propVal -> {

  var prop = type.TypeInfo.getProperty( propName as String )

  if( prop.Writable ) {

    prop.Accessor.setValue( instance, CommonServices.getCoercionManager().convertValue( transformObj( propVal, prop.FeatureType ), prop.FeatureType ) )

  }

})

// maybe commit object here?

return instance

} else if( val typeis List ) {

return val.map( \ o -> transformObj( o, type.TypeParameters.first() )  )

} else {

print( "expected: ${type.Name}, found ${typeof val}" )

return val

}

}

Obviously it needs to be more robust (list handling is very raw, error handling is non-existant, should we commit the db objects to the db up front? If not, how can a user figure out what to commit?) but at least the reflection appears to work reasonably well.

Cheers,
Carson

On Jun 9, 2011, at 8:20 AM, kprevas wrote:

You're right, we don't go more than one level deep. I can look in to this.

Reply to this email directly or view it on GitHub:
#44 (comment)

from ronin.

Related Issues (20)

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.