Currently in all of my projects im using JSON Model for all client side manipulations. But XML Model also do the same.
Can someone help me the exact differences between XML Model
and JSON Model. And why developers are preferring JSON Model over XML Model??
It is easier to use JSON in JavaScript, as it is derived from JavaScript.
Some JSON benefits:
less verbose
easier to read and write
easily accessible with JSON.parse() function. XML parsing is inherently more work in JavaScript (XMLModel would be doing the work, but it is still more work being done).
Some XML benefits:
schema support
comment support
Related
Currently, we are exploring CodeEffects for our one of the rule engine proposal.
We have a dynamic type which is a JSON string. During runtime, we need to apply the rule for JSON using CodeEffects. Is it support for FlexSource or any other possibility.
You need to serialize your Json string into a .NET object, fill it with data if needed, and pass that object to the Evaluator together with your rule for evaluation. The FlexSource is designed specifically to support this kind of scenarios. Download the FlexSource demo project from Code Effects website and replace the XML data file used there as the source object with your Json.
I'm in the process of developing a custom datasource to interface with a REST API. In the example provided on the CakePHP website they return the data from a READ operation in this structure:
Array(
'ModelName'=>Array(all the actual data here)
)
The code looks like:
return array($model->alias => $results);
Is there any specific reason to return the results this way or can I just return as:
return $results;
My concern is that if I don't return in the CakePHP specific format I might not be able to use some other built in functionality. I don't see anything specific about the need for this structure. Any insight would be appreciated.
It comes down to CakePHP's data structure guidelines. The reason Cake uses the model name as the array key and the results as the value is because it makes it very easy to read when you have multiple tables returned in the same query - after all, Cake models are relational database maps and are built to be associative.
How you use the results from Cake's data results is up to you. Yes, there are times when the model name prefix annoys me and I find it useless, but most of the time it can be very useful to help you distinguish between multiple associated table results in one query.
If you don't think you'll ever need this and don't mind breaking Cake's data structure conventions, there's nothing wrong with breaking away from it - but if I were you I would create your API interface in a way where it conforms exactly to the structure that their built in datasources return (for current and future compatibility reasons mainly).
More info on creating a REST API datasource is here in the manual.
we have a very dynamic metamodel which changes frequently. We don't use EF but an own Database-Technology.
As we didn't find any good documentation on how the server-side metamodel has to be created "by hand", we decided to create the client-side metamodel and import this one into breeze when loading the application.
Now we have the problem, that eventhough we tell breeze to get all Person-Objects and take 3, the server expands all associations and returns more than 3 results. Breeze then cuts the result on the client to 3 and fills the properties.
Now I'm wondering, if we just didn't understand some of the concepts. All we want to do is to tell breeze dynamically how our metamodel looks like without using EF or NHybernate. Is there any documentation on that?
The only documentation on a Schema I found was this one:
http://www.breezejs.com/documentation/metadata-schema
But it only explains the client-Side-Metamodel but not the Schema that our Server-Side would have to generate. As far as I see it, the Server-Side-Metamodel gets translated into the client-Side-Metamodel anyways.
Would be nice if someone could clarify or provide a link with all the "basic information" about the topic.
The client metadata is for the Breeze client. The server shouldn't need it, because it already knows what the domain model looks like. The content of server-side metadata typically comes from the database and/or the mapping layer, when using an ORM.
Breeze's server-side WebApi filters attempt to apply the OData query parameters to the IQueryable that comes from the data provider (EF, NH, or whatever). If the data provider's LINQ implementation is incomplete, that could cause the problem you mentioned, in which take didn't work.
Unfortunately, the metadata-schema document is out-of-date. The structure of the Breeze metadata JSON format has changed since then. You are better off looking at an example of current metadata, and following the Metadata by Hand guidelines.
I need to write a rest client (in Java - using RestEasy) that can consume JSON responses. Regarding the need for the rest client (or wrapping service) to translate the JSON responses to a Java type, I see the following options:
1. map the response to a string and then use JsonParser tools to extract data and build types manually.
2. Use JAXB annotated POJOs - in conjunction with jackson - to automatically bind the json response to an object.
Regarding 2, is it desirable / correct to define an XSD to generate the JAXB annotated POJOs? I can advantages to doing this using, e.g. reuse by an XML client.
Thanks.
I'm a fan of #2.
The reasoning is that your JAXB annotated model objects essentially are the contract for the business/domain logic that you're trying to represent on a transport level, and POJOs obviously give you excellent control over getter/setter validation, and you can control your element names and namespaces with fine granularity.
With that said, I like having an additional "inner" model of POJOs (if necessary, depending on problem complexity/project scope) to isolate the transport layer from the domain objects. Also, you get a nice warm feeling that you're not directly tied to your transport layer if things need to change internally in your business/domain object representation. A co-worker mentioned Dozer, a tool for mapping beans to beans, but I have no direct experience with it to comment further.
I'm not a fan of generating code from XSDs. Often the code is ugly or downright unreadable; and managing change, however subtle or insignificant can introduce unexpected results. Maybe I'm wrong about that but I require good unit-tests on a proven model.
This is based on my personal experience writing a customer-facing SDK with a hairy XML-over-HTTP (we don't call it REST) API. JAXB/Jackson annotated POJOs made it relatively painless. Hope that helps.
I am working on a web application which is being developed using GWT. I am also using OWL ontologies and Jena framework to structure semantic contents in the application.
A simple function in the application would be getting some data from the user and send it to the servers side to be stored as a data graph using the ontology. I suppose one way would be to store the data as java class objects equivalent to the ontology classes and send them using the GWT async communication. To convert OWL classes to java, I used Jastor.
My question is that after the server receives the java class, is it possible to easily convert is to an OWL individual and add it to the data graph, using the functions of Jena and/or Jastor? For instance in the server side interface implementation we call something like this:
Public void StoreUser (User userObj) {
//User: a Jastor created java class. userObj is instantiated using the user data on the client side.
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
//Open the ontology here using inputstream and ontModel.read!
Individual indiv = (Individual) userObj.resource();
//Add the individual to the model here! }
Unfortunately I wasn't able to find any Jena function that can add an existing individual to the model.
Would you suggest another way to pass the ontology data to server side and store it, rather than using Jastor created classes (for instance using an XML file)?
Thanks for your help
There are two parts to the answer. First, an Individual is a sub-class of a Jena Resource, which is definitely something that you can add to a model. However, individual resources, or properties or literals are not stored in a Model. A Model stores only triples, represented as Statement objects in the Java API. So to add some resource to a model, you have to include it in a triple.
In Jena, an individual is defined as a subject of a triple whose predicate is rdf:type and whose object is not one of the built-in language classes. So if you have:
ex:my_car rdf:type ex:Ferrari .
ex:Ferrari rdf:type owl:Class .
(note: this example is entirely fictitious!), then ex:my_car would be an individual, but ex:Ferrari would not (because OWL Class is a built-in type). So, to add your individual to your model, you just need to assert that it is of some type. Since I don't know GWT and don't use Jastor, I can't say whether the type association that is normally part of a Jena Individual is retained after serialization. I suspect not, in which case you'll need to have some other means of determining the type of the individual you want to add, or use a different predicate than rdf:type to add the resource to the the Model.
All that said, personally I probably wouldn't solve your problem this way at all. Typically, when I'm working with client-side representations of server-side RDF, I send just the minimal information (e.g. URI and label) to the client as JSON. If I need any more data on a given resource, I either send it along with the initial JSON serialization, or it's just an Ajax call away. But, as I say, I don't use GWT so that advice may not be of any use to you.