We want to create a NMARoute without calling [NMACoreRouter calculateRouteWithStops: ...] as it send an unnecessary HTTP call to here.com. Because we already have every information to create a NMARoute object, we just want to initialize it. Unfortunately there is no public initializer. Is there any other approach to initialize a NMARoute object?
Take a look at route serialization:
https://developer.here.com/documentation/ios-premium/topics/route-serialization.html
Basically, the gist of it is that you can create a route based on an NSData object:
https://developer.here.com/documentation/ios-premium/topics_api_nlp_hybrid_plus/interfacenmaroute.html#topic-apiref__routefromserializedroute-colon-error-colon
Note:
The route data depends directly on the map data on your device. The routing data can become obsolete with a map update, and deserialization may not be valid.
Related
I have some data that I need to persist through multiple actions within my Grails app. Due to the nature of the data, I would prefer not to store the data in the session. Here is an example of what I would like to do.
class MyController{
def index(){
MyObject object = MyObject.new(params.first, params.second, params.third)
[gspObject:object]
}
def process(){
MyObject object = params.gspObject
//continue from here
}
}
In my GSP if I do
<g:form action="process" params="[gspObject:gspObject]">
Then I get the error
Cannot cast object 'net.package.MyObject#699c14d8' with class 'java.lang.String' to class 'net.package.MyObject'
My question is, If I want to get the object back that I sent to the gsp, how can I get that? Is there some kind of scope that I can save the object in that would be a little safer then session? Is there a way to pass the object into the page itself and pass it back in the next request?
Grails has many layers, but at the bottom you have plain old HTTP just like in any web app. It's a stateless protocol, and you send a text or binary response, and receive text or text + binary requests. But you can't expect to be able to send an arbitrary object to a web browser in HTML and receive it back again in the same state as when you sent it - where is this Java/Groovy JVM object going to be stored in the browser?
You have basically two options. One is to store it at the server, which is less work because it remains as the same object the whole time. The session is a good location because it's coupled to the user, is created on-demand and can automatically time out and be removed, etc. The other is to do what you're trying to do - send it to the client and receive it back - but you are going to have to serialize it from an object (which could be a complex object containing arbitrarily many other objects) and deserialize it from the format you used on the client back into Java/Groovy objects.
JSON is a good option for serialization/marshalling. You could store the stringified object in a hidden form element if your page uses a form, or in a querystring arg if you click a link from this page to the next in the workflow. Don't send all of the object's data though, only what you need to rebuild it. Anything that's available in the database should be referenced by id and reloaded.
Something like
[gspObject: object as JSON]
or
[gspObject: [first: object.first, first: object.firstsecond, ...] as JSON]
will get it in the correct format for sending, and then you can parse the JSON from the request to reinstantiate the instance.
According to the document on command objects and data binding. Once you read the params object, that object can never be reused again.
From the documentation:
Binding The Request Body To Command Objects
http://grails.org/doc/2.3.x/guide/theWebLayer.html#commandObjects
Note that the body of the request is being parsed to make that work. Any attempt to read the body of the request after that will fail since the corresponding input stream will be empty. The controller action can either use a command object or it can parse the body of the request on its own (either directly, or by referring to something like request.JSON), but cannot do both.
I'm trying to view the parameters within a filter (which is hit before the controller is requested). Would logging the parameters to a log cause the controller to get a null param object? From the documentation that looks to be the case. However, how can I get access to the params without wiping them out in the filter?
Once you read the params object, that object can never be reused
again.
That is not correct. You can read request parameters over and over again. What cannot be read over and over again is the body of the request. The body and the request parameters are 2 different things.
When I POST a Core Data managed object using RestKit, RestKit doesn't update the existing object but creates a new object instead.
The returned JSON always contains the newly created object, but wraps it into a plural keyed array. I found that if I change this to just the one object, the updating works as expected. However, I would like to keep the array in the response so that all responses are consistently in the plural form.
Is there any way I can make RestKit update the record, even when returned from the server wrapped in an array?
Possible solution: identificationAttribute?
On my entities I have an identificationAttribute called remoteID. This is the primary unique key of the record. This will be 0 before the POST, because the object is not yet on the server. I thought that by adding a second identificationAttribute called insertionID, setting that before the POST, and then returning it in the response, would allow RK to find the existing entity in the local store. Alas, it didn't work.
What did work however, was setting the remoteID before the POST, to the next auto increment value on the server! What could explain that it works with remoteID, but not with a second insertionID?
Example request
{
"user": {
"email": "example#example.com"
}
}
Response
{
"users": [{
"email": "example#example.com"
}]
}
I would like to keep the array in the response so that all responses are consistently in the plural form.
You shouldn't, because this is an individual request and response, not a composite.
Your idea about identificationAttribute is correct, but doesn't apply when the response is an array. The array is the trigger (or one of the possible triggers) to abandon the match with the source object and create new objects. Changing this would be hard.
Without knowing more about your real situation, 2 alternatives:
Change the JSON
POST a dictionary instead of the real object and then you won't have a duplicate
When you use multiple identification attributes, all must match for the destination object to be found.
Take care - don't create multiple mappings for the same entity with different identification attributes or you will most likely be debugging the lookup cache for a long time trying to work out what's happening...
If the identity matches before the request is made then the array isn't an issue. To explain the above in more detail:
When you POST an object, RestKit expects to get that object back. So, if you POST one object and get an array back it doesn't know what to do, because it can't map an array into an object. So, it tries to lookup based on the identification attribute (if they exist). If the POSTed object didn't have an id and the returned object does then it will never match. If you set it before POSTing then it will match.
Is there any way to use RestKit in an unrestful way?
For example, If I set up an object mapping as such:
[manager.router routeClass:[BBMediaResourceCreate class]
toResourcePath:#"/mediaresources"
forMethod:RKRequestMethodPOST];
RestKit will expect that I post a BBMediaResourceCreate object and receive one back also.
My API however, for reasons I won't go into, is not RESTful compliant in some situations. Rather than receive the newly created resource, I'll get something more like:
{ Model: { Success:true} }
or something similar
Is there a way to map a RestKit post to post a resource of one type but expect a response of another type?
Thanks.
When using v0.10 you can simply set resourcePath:#"/"and respond to
- (void)objectLoaderDidLoadUnexpectedResponse:(RKObjectLoader *)objectLoader
or
- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObject:(id)object
and handle the response in [objectLoader response] like you want. Keep in mind that posting to that resource then needs an explicit, manually set path.
I had to change an application that was making a call clientside (JS) to get back data that comes back as JSON. I had to move the call server side, and I'm using rails to return the data.
To reference the object I need, with the object being returned called "data" I was able to call it JS like so:
data.photos[0].tags[0].mouth_left.x
I'm very new to rails, I have the call populating a variable called face_values, I think I should call to_json on it next, but how do I reference the arrays and nested objects within?
Even a point in the right direction would be great, thank you.
parsing JSON in Rails is as follows:
parsed_json = ActiveSupport::JSON.decode(your_json_string)
or check out this link
They claim they are 21.5x faster than ActiveSupport::JSON.decode