Coder Social home page Coder Social logo

piriti's Introduction

What the heck is piriti

Piriti (Maori for "bridge") is a JSON and XML mapper for GWT based on reasonable defaults, a handful of annotations and deferred binding. The following code snippets show the basic ideas behind Piriti.

XML Mapping

In case you have the following XML document

<vub readonly="true">
    <name>Foo</name>
    <createdAt>08.01.2010</createdAt>
    <count>20</count>
</vub>

and the model class

public class VirtualUserBundle
{
    interface VubReader extends XmlReader<VirtualUserBundle> {}
    public static final VubReader XML = GWT.create(VubReader.class);

    int count;
    String name;
    @Path("@readonly") boolean readonly; 
    @Format("dd.MM.yyyy") Date createdAt;
}

you can turn the XML into an instance of VirtualUserBundle by calling

Document document = new XmlParser().parse(xmlAsString); 
VirtualUserBundle vub = VirtualUserBundle.XML.read(document);

JSON Mapping

JSON mapping works very similar. In case you have the following JSON data

{ "readonly": true, "name": "Foo", "createdAt": "08.01.2010", "count": 20 }

and the model class

public class VirtualUserBundle
{
    interface VubReader extends JsonReader<VirtualUserBundle> {}
    public static final VubReader JSON = GWT.create(VubReader.class);

    int count;
    String name;
    boolean readonly; 
    @Format("dd.MM.yyyy") Date createdAt;
}

you can map the JSON data to an instance of VirtualUserBundle by calling

String jsonString = ... // the above JSON data
VirtualUserBundle vub = VirtualUserBundle.JSON.read(jsonString);

piriti's People

Contributors

gmlewis avatar hpehl avatar lathil avatar meriouma avatar sannysanoff 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

piriti's Issues

Node annotated with @Native is not serialised - does @Native work at all?

I have a class which looks something like this (names changed to protect the innocent ;):

package com.com.com;

import name.pehl.piriti.commons.client.Native;
import name.pehl.piriti.xml.client.XmlWriter;
import name.pehl.totoe.xml.client.Node;

class Request
{
    public interface ReqWriter extends XmlWriter<Request> {}
    public static final ReqWriter WRITER = GWT.create(ReqWriter.class);

    @Native Node anXMLFragment;
}

I assign a Node which I have previously obtained from a NodeList generated by totoe's selectNodes to anXMLFragment, but when I serialise a Request using Request. WRITER. toXml (req), the XML element is empty: <anXMLFragment />.

I walked through in the debugger, and saw this generated code:

                // parsing template name/pehl/piriti/rebind/xml/writer/property/any.vm
                if (logger.isLoggable(FINE)) 
                {
                    logger.log(FINE, "Processing name.pehl.totoe.xml.client.Node anXMLFragment");
                }
                name.pehl.totoe.xml.client.Node value1007 = null;
                                                            value1007 = model.anXMLFragment;
                                                                        boolean value1007CreateRequired;
    if (value1007 != null)
{
            XmlWriter<name.pehl.totoe.xml.client.Node> value1007Writer = xmlRegistry.getWriter(name.pehl.totoe.xml.client.Node.class);
        if (value1007Writer != null)
        {
            XmlBuilder nestedXmlBuilder = new XmlBuilder("anXMLFragment");
            ((AbstractXmlWriter<name.pehl.totoe.xml.client.Node>)value1007Writer).appendModel(nestedXmlBuilder, value1007);
            xmlBuilder.append(nestedXmlBuilder);
        }
        else
        {
           xmlBuilder.append("anXMLFragment");
        }

The call to xmlRegistry.getWriter returns null, and so only the empty element is written. I looked in the xmlRegistry instance, and can see that there is indeed no writer for name.pehl.totoe.xml.client.Node in its set of writers.

What's going on here? Do I need to do something in order to get a “pass-through” writer for Node added to the registry? … or am I doing something else wrong, … or is this a bug?

Can't build sources due to test failures

just downloaded zip and tried to build and there is a test failure

testRead(name.pehl.piriti.client.converter.JsonBackAndForthTest) Time elapsed: 0.535 sec <<< FAILURE!
junit.framework.AssertionFailedError: Remote test failed at xx.xx.xx.xxx / Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
expected: <11>, actual: <6>
at junit.framework.Assert.fail(Assert.java:193)
at junit.framework.Assert.failNotEquals(Assert.java:198)
at junit.framework.Assert.assertEquals(Assert.java:94)
at junit.framework.Assert.assertEquals(Assert.java:43)
at name.pehl.piriti.client.converter.AbstractBackAndForthTest.assertDateTime(AbstractBackAndForthTest.java:46)
at name.pehl.piriti.client.converter.AbstractBackAndForthTest.assertBackAndForth(AbstractBackAndForthTest.java:19)
at name.pehl.piriti.client.converter.JsonBackAndForthTest.testRead(JsonBackAndForthTest.java:18)
at name.pehl.piriti.client.converter.__JsonBackAndForthTest_unitTestImpl.doRunTest(__JsonBackAndForthTest_unitTestImpl.java:10)
at junit.framework.TestCase.runTest(TestCase.java:62)
at com.google.gwt.junit.client.GWTTestCase.runBare(GWTTestCase.java:188)
at com.google.gwt.junit.client.GWTTestCase.__doRunTest(GWTTestCase.java:129)
at com.google.gwt.junit.client.impl.GWTRunner.runTest(GWTRunner.java:390)
at com.google.gwt.junit.client.impl.GWTRunner.doRunTest(GWTRunner.java:318)
at com.google.gwt.junit.client.impl.GWTRunner.access$9(GWTRunner.java:312)
at com.google.gwt.junit.client.impl.GWTRunner$TestBlockListener.onSuccess(GWTRunner.java:107)
at com.google.gwt.junit.client.impl.GWTRunner$TestBlockListener.onSuccess(GWTRunner.java:1)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:249)
at sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:724)

testRead(name.pehl.piriti.client.converter.JsonBackAndForthTest) Time elapsed: 0.553 sec <<< FAILURE!
junit.framework.AssertionFailedError: Remote test failed at xx.xx.xx.xxx / Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19
expected: <11>, actual: <6>
at junit.framework.Assert.fail(Assert.java:193)
at junit.framework.Assert.failNotEquals(Assert.java:198)
at junit.framework.Assert.assertEquals(Assert.java:94)
at junit.framework.Assert.assertEquals(Assert.java:43)
at name.pehl.piriti.client.converter.AbstractBackAndForthTest.assertDateTime(AbstractBackAndForthTest.java:46)
at name.pehl.piriti.client.converter.AbstractBackAndForthTest.assertBackAndForth(AbstractBackAndForthTest.java:19)
at name.pehl.piriti.client.converter.JsonBackAndForthTest.testRead(JsonBackAndForthTest.java:18)
at name.pehl.piriti.client.converter.__JsonBackAndForthTest_unitTestImpl.doRunTest(__JsonBackAndForthTest_unitTestImpl.java:10)
at junit.framework.TestCase.runTest(TestCase.java:62)
at com.google.gwt.junit.client.GWTTestCase.runBare(GWTTestCase.java:188)
at com.google.gwt.junit.client.GWTTestCase.__doRunTest(GWTTestCase.java:129)
at com.google.gwt.junit.client.impl.GWTRunner.runTest(GWTRunner.java:390)
at com.google.gwt.junit.client.impl.GWTRunner.doRunTest(GWTRunner.java:318)
at com.google.gwt.junit.client.impl.GWTRunner.access$9(GWTRunner.java:312)
at com.google.gwt.junit.client.impl.GWTRunner$TestBlockListener.onSuccess(GWTRunner.java:107)
at com.google.gwt.junit.client.impl.GWTRunner$TestBlockListener.onSuccess(GWTRunner.java:1)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:249)
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:724)

No serialization of inherited type

What steps will reproduce the problem?

  1. create class Holder with JsonWriter
  2. create abstract class Property
  3. create class PropertyInteger with JsonWriter
  4. set holder.property to a value of PropertyInteger
  5. serialize holder. It will have "property: null"

What is the expected output? What do you see instead?

Piriti should just take the runtime value and use the correct Writer.

What version of the product are you using?

0.8, GWT 2.4 devmode

I forgot to mention PropertyInteger extends Property

Unmarshal "null" to "no tag" instead of empty tag

Currently Pirity marshals "null" to empty tags:

String foo = null;

becomes

<foo\>

Unmarshalling that back to a java object with JaxB will cause "foo" to be an empty string, rather than null.

Would it be possible to add the ability to omit the tag when marshalling "null"s?

Compile time errors using @CreatWith in web mode

I’m hoping to serialize a list of objects to XML using polymorphic references. My setup seems to work successfully in GWT dev mode, however I run into compile time errors on my official build machine. I have a base class with xml reader/writers defined, subclasses with xml reader/writers also defined, and a wrapper class that contains only a list of base class objects, also with its own xml reader/writer. The compilation error involves the wrapper class, and seems to come from the fact that it both utilizes the @createwith annotation, and also has xml readers/writers defined for it. If I comment out the @createwith annotation, my project compiles successfully. Below is the wrapper class in its entirety. I have attached the error log, which contains 2 distinct errors. First is a classnotfoundexception, but I noticed that this disappears when I comment out the reader/writer in the wrapper class, so perhaps it is a symptom of the second error? Second is an IllegalArgumentException, complaining of object is not an instance of declaring class.

Is it that the existence of the @createwith tag is somehow mucking up compilation? Any insight you could provide would be greatly appreciated. For reference, I am using the following versions:

  • GWT 2.4
  • Gin 2.1.1
  • Guice 3.0
  • Piriti 0.8 (same results swapping in 0.10)
  • Totoe 0.4
  • Velocity 1.7
public class SavedWorkspace {
    public interface SavedWorkspaceReader extends XmlReader<SavedWorkspace> {}
    public static final SavedWorkspaceReader XmlReader = GWT.create(SavedWorkspaceReader.class);

    public interface SavedWorkspaceWriter extends XmlWriter<SavedWorkspace> {}
    public static final SavedWorkspaceWriter XmlWriter = GWT.create(SavedWorkspaceWriter.class);

    @CreateWith(WorkspaceViewStateCreator.class)
    @Path("viewStates/view")
    private List<WorkspaceViewState> viewStates;

    public SavedWorkspace() {       
    }

    public SavedWorkspace(List<WorkspaceViewState> viewStates) {
        this.viewStates = viewStates;
    }

    public List<WorkspaceViewState> getViewStates() {
        return viewStates;
    }

    public void setViewStates(List<WorkspaceViewState> viewStates) {
        this.viewStates = viewStates;
    }
 }

Attributes not added correctly to nodes with text-only content

What steps will reproduce the problem?

  1. Create a POJO marked-up as such:
public class SomeClass
{
@Path("field")
public String text;
@Path("field/@name")
public String name;
}
  1. Create an instance of SomeClass, give both fields values and attempt to map to XML with Piriti.

What is the expected output? What do you see instead?

Expected:

<?xml version="1.0" encoding="UTF-8"?>
<someClass>
 <field name="nameValue">value</field>
</someClass>

Actual result:

<?xml version="1.0" encoding="UTF-8"?>
<someClass>
 <field>value</field>
 <field name="nameValue"/>
</someClass>

What version of the product are you using? On what operating system?
0.8, Java 1.6, GWT 2.4.0

Please provide any additional information below.

Mapping XML -> POJO works fine, it's just POJO -> XML that breaks.

enum ordinal serialization

Enums serialized via it's ordinal value will get sent in JSON notation as an integer. In piriti in the enum.vm template for the reader there is a check if the sent value is a string. So currently we cannot use enum ordinal serialization. Even if we tried to implement a converter it would not kick in, as it is only called after the string check.

We propose an extension to the enum.vm reader template like the following:

  • if it's not a string try to get the enum value via it's ordinal value

so something like this (beware, not syntax checked or tried)

if (${jsonValue}.isNull() == null) 
{
    JSONString jsonString = ${jsonValue}.isString();
    if (jsonString != null)
    {
// [..]
    } 
    else 
    {
        $valueType[] values = $valueType.values();
        if (0 <= $jsonValue && $jsonValue < values.length) 
                {
            $value = values[$jsonValue];
        }
    }
}

would ensure the reader works out of the box with enums serialized as name and as ordinal without any need for configuration.

For the writer something similar, but with some new configuration switch.

if ($value != null)
{
    #if ($property.converter)
        #createConverter()
        String $valueAsString = ${converter}.serialize($value);
    #else
        #if ($property.asOrdinal)
            String $valueAsString = $value.ordinal();
        #else
            String $valueAsString = String.valueOf($value);
        #end
    #end
    if (isNumber($valueAsString))
    {
        out.append($valueAsString);
    }
    else
    {
        out.append(JsonUtils.escapeValue($valueAsString));
    }
}
else
{
    out.append("null");
}

Startup-Exception

What steps will reproduce the problem?

I added the maven-dependencies as shown in the wiki, added the json-inherits to gwt.xml ( name.pehl.piriti.json.JSON ) and received this error at startup:

Loading inherited module 'name.pehl.piriti.json.JSON'
Loading inherited module 'com.google.gwt.inject.Inject'
[ERROR] Unable to find 'com/google/gwt/inject/Inject.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] Line 5: Unexpected exception while processing element 'inherits'

What version of the product are you using? On what operating system?

GWT 2.4, Eclipse 4.2.0, m2e 1.1.0 on Windows 7

Please provide any additional information below.

Looks to me like GIN is not available, it is not listed as a dependency for piri ( in eclipse m2e dependency hierarchy ) but seems to be neccessary.

Compile Issue with v0.10

I have the following envrioment
GWT 2.5.1
Piriti 0.10
GWT module has the configured

I have all required libs included on my classpath

I traced it down to when I call read or toXml. if i comment these lines, the program compiles..

data = READER_WRITER_REFERRAL_DETAIL.getXmlWriter().toXml(detail,"detail");
and
detail = READER_WRITER_REFERRAL_DETAIL.getXmlReader().read(doc);

any ideas on how to correct this?

Here is the full source
/**

import name.pehl.piriti.xml.client.XmlReaderWriter;
import name.pehl.totoe.xml.client.Document;
import name.pehl.totoe.xml.client.XmlParser;

import com.google.gwt.core.shared.GWT;
import x.x.x.x.ReferralDetail;
import x.x.x.x.ReferralLabel;

public class RMSXmlUtility {
public interface ReferralDetailReaderWriter extends XmlReaderWriter {}
public static final ReferralDetailReaderWriter READER_WRITER_REFERRAL_DETAIL = GWT.create(ReferralDetailReaderWriter.class);

public interface ReferralLabelReaderWriter extends XmlReaderWriter<ReferralLabel> {}
public static final ReferralLabelReaderWriter READER_WRITER_REFERRAL_LABEL = GWT.create(ReferralLabelReaderWriter.class);


public static ReferralDetail getReferralDetail(String xml) {
    ReferralDetail detail = null;
    try {
        Document doc = new XmlParser().parse(xml);
        detail = READER_WRITER_REFERRAL_DETAIL.getXmlReader().read(doc);
        doc = null;
    }catch(Exception e) {
        GWT.log(e.getLocalizedMessage());
    }
    return detail;
}
public static String toXmlFromReferralDetail(ReferralDetail detail) {
    String data = null;
    try {
        data = READER_WRITER_REFERRAL_DETAIL.getXmlWriter().toXml(detail,"detail");
    }catch(Exception e) {
        GWT.log(e.getLocalizedMessage());
    }
    return data;
}

}

*/

When I run the GWT Compiler I ger the following

Here is the error

Compiling module x.x.x.x.RMS

Computing all possible rebind results for 'name.pehl.piriti.xml.client.XmlWriter'
Rebinding name.pehl.piriti.xml.client.XmlWriter
Invoking generator name.pehl.piriti.rebind.xml.XmlWriterGenerator
[ERROR] You must use a subtype of XmlWriter in GWT.create(). E.g.,
interface ModelReader extends XmlWriter {}
ModelReader reader = GWT.create(ModelReader.class);
[ERROR] Errors in 'gen/x/x/apps/rms/client/ui/utility/RMSXmlUtility_ReferralDetailReaderWriterImpl_RMSXmlUtility_ReferralDetailReaderWriterImplXmlWriterImpl.java'
[ERROR] Line 766: Failed to resolve 'name.pehl.piriti.xml.client.XmlWriter' via deferred binding
Computing all possible rebind results for 'name.pehl.piriti.xml.client.XmlWriter'
Rebinding name.pehl.piriti.xml.client.XmlWriter
Invoking generator name.pehl.piriti.rebind.xml.XmlWriterGenerator
[ERROR] You must use a subtype of XmlWriter in GWT.create(). E.g.,
interface ModelReader extends XmlWriter {}
ModelReader reader = GWT.create(ModelReader.class);
[ERROR] Errors in 'gen/x/x/apps/rms/client/ui/utility/RMSXmlUtility_ReferralDetailReaderWriterImpl_RMSXmlUtility_ReferralDetailReaderWriterImplXmlWriterImpl.java'
[ERROR] Line 818: Failed to resolve 'name.pehl.piriti.xml.client.XmlWriter' via deferred binding
Computing all possible rebind results for 'name.pehl.piriti.xml.client.XmlWriter'
Rebinding name.pehl.piriti.xml.client.XmlWriter
Invoking generator name.pehl.piriti.rebind.xml.XmlWriterGenerator
[ERROR] You must use a subtype of XmlWriter in GWT.create(). E.g.,
interface ModelReader extends XmlWriter {}

How to convert POJO->JSON for List<Objects>?

What steps will reproduce the problem?

  1. Create a BaseModel. It has a 'String modelType' property which represents the class name to be created when response comes back.
  2. Create TeacherModel, StudentModel which extend BaseModel.
  3. Create a RequestResponseModel which also extends BaseModel but it has three important properties (i) String serviceMethodName (ii) List payload (iii) String callbackNotificationName and some other properties.
  4. While sending request to server, 'payload' has an Integer and one or more of the above Models which are needed on server side.
  5. When response comes back, payload contains the results, which are typically one or more of the above Models.
  6. What is the expected output? What do you see instead?

    Everything works fine with the above setup except Writer does not generate json for the Models in payload. It works fine for Integer and String etc in the payload but not for Models. Looks like it just writes toString() of the Model object. How can I handle that?

    What version of the product are you using? On what operating system?

    I downloaded the latest one.

    Please provide any additional information below.

    I am using GWTP with Piriti.

Problem using GWT 2.5 RC1 and Super DevMode

What steps will reproduce the problem?

  1. When trying to use the new GWT 2.5 RC1 super devmode the compiler shows the following error:
Linking modules
   Bootstrap link for command-line module 'XXXXX'
      Linking module 'XXXXX'
         Invoking Linker Cross-Site-Iframe
            [ERROR] The Cross-Site-Iframe linker does not support <script> tags in the gwt.xml files, but the gwt.xml file (or the gwt.xml files which it includes) contains the following script tags: 
jsonpath.js
In order for your application to run correctly, you will need to include these tags in your host page directly. In order to avoid this error, you will need to remove the script tags from the gwt.xml file, or add this property to the gwt.xml file: <set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>
[ERROR] shell failed in doSlowStartup method

Is possible to fix this by adding the file directly to the html file and seting the parameter, but it would be nice if you could mayble avoid using the script tag to fix this issue.

I guess instead of putting the script files in the Module.xml file it probably makes sense to add them to a ClientBundle and use SCriptInjector to inject them

using mappings on XmlReaderWriter doesn't generate with correct paths

@mappings({
@mapping(value="fName", path="FirstName"),
@mapping(value="lName", path="LastName")
})
interface ReaderWriter extends XmlReaderWriter{}

with public class Name{
String fName;
String lName"
}
generates a reader and writer looking for the paths lName and fName in the xml. It works correctly if you create and separate reader and writer using the mappings with following Xml:

<Name> <FirstName>john</FirstName> <LastName>doe</LastName> </Name>

Map property to XML attribute

I'm using piriti for XML mapping in GWT application. I have not found the ability to map XML value. For example for this class:

public class Option
{
   private String id;
   private String text;
}

I want to get this XML:

<option id="1">Java</option>

With pirti I only can get this:

<option id="1">
<text>Java</text>
</option>

My question is whether there is a possibility to get XML value or maybe are you going to upgrade piriti?

A mapping like this

public class Option {

    @Path("@id") private String id;
    @Path("text()") private String name;

    // getters & setters
}

does work for reading, but not for writing.

Serializing collection in XML while keeping class name of collection item as tag name in produced XML

Hello Harald,

I am using Piriti on a Restlet / Gwt project fro sole time now. I had a probleme while serializing a list of objects ex: List with the objects in the list all extending the original type. In the XML produced I need to have the list elements with theirs tag name to be the name of the extending class. Actually the list elements names are derived from the list name ....

Per example I have a List, and objects Volkswagen, Saab and Renault all extend Car. Say I have such a list and objects Volkswagen, Saab and Renault in it. I'll need the poduced XMl to look like:

To manage that, I had to modify the Velocity templates in pririt-dev, in /src/main/resources/name.pehl.pririti.rebind.xml.writer.property.collection.vm, begining in lines 20, from

if (currentValue != null)
{
#parse($property.templates.elementType)
}
else
{
collectionXmlBuilder.append(nestedPath);
}

to:

if (currentValue != null)
{
#if (!$property.xpath)
String nestedElementName = currentValue.getClass().getName();
nestedPath = nestedElementName.substring(nestedElementName.lastIndexOf(".")+1).toLowerCase();
#end
#parse($property.templates.elementType)
}
else
{
collectionXmlBuilder.append("$property.pathOrName");
}

This way, if in a XMLWrtiter mapping for a collection element, I do not indicate the path, the class name of each collection element is used as the name of the tage, example:
@mapping( value="childrens", path="" ),

I do not have the same problem with the XMLReader part, because I can use this expression:
@mapping( value="childrens", path="child::*", createWith= ObjCreator.class),

Do you think it is something we could push back into piriti ?

Thanks
Laurent.

compile warning for gwt 2.8

for your info

[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/json/client/AbstractJsonWriter.java:66
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/json/client/AbstractJsonWriter.java:75
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/json/client/AbstractJsonWriter.java:85
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/json/client/AbstractJsonWriter.java:96
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/json/client/AbstractJsonWriter.java:107
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/json/client/AbstractJsonWriter.java:118
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/json/client/AbstractJsonWriter.java:129
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/converter/client/LongConverter.java:17
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/converter/client/BooleanConverter.java:27
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/converter/client/IntegerConverter.java:17
[WARN] Call to Enum method valueOf when enum obfuscation is enabled: name/pehl/piriti/converter/client/DoubleConverter.java:17

Mapping of fields to attributes not working in subclasses

What steps will reproduce the problem?

  1. I declare an Xmlreader for the class Obj this way:
@Mappings({
    @Mapping( value="display", path="@display"),
    @Mapping( value="displayName", path="@displayName"),
    @Mapping( value="href", path="@href", convert= UriConverter.class),
    @Mapping( value="icon", path="@icon", convert= UriConverter.class),
    @Mapping( value="is", path="@is", convert = ContractConverter.class),
    @Mapping( value="isNull", path="@isNull"),
    @Mapping( value="name", path="@name"),
    @Mapping( value="status", path="@status"),
    @Mapping( value="writable", path="@writable"),
    @Mapping( value="childrens", path="child::*", createWith= ObjCreator.class)
})
public interface ObjXmlReader extends XmlReader<Obj>{}
  1. I declare an XmlReader for class OP ( Op extends Obj) this way:
@Mappings({
    @Mapping( value="in", path="@in", convert= ContractConverter.class),
    @Mapping( value="out", path="@out", convert= ContractConverter.class)
})
public interface OpXmlReader extends XmlReader<Op>{}
  1. What is the expected output? What do you see instead?
    OpXmlReader should be able to mapp fields to associates xml attributes ( Pojo ->Xml). It doesn't.
    In function readProperties(..) of OpXmlReaderImpl I see: value = element.selectValue("display",REMOVE),
    but in readProperties(..) of ObjXmlReaderImpl the same line is : value = element.selectValue("@display",REMOVE).

It look like in subClasses, Piriti forgot that the class files was mapped to an attribute of the current element, and instead look for an child element ...

As a result I can't mapp any attributes to subclasses of class Obj.

What version of the product are you using? On what operating system?

Pririti 0.8, Restlet 2.05, Gwt 2.4, Windows XP, Firefox 3.6

https://code.google.com/p/piriti/issues/attachmentText?id=58&aid=580002001&name=Op.java&token=NNIGCtYwlCdmNqfxfDZ_uyyaKcU%3A1351504668855
https://code.google.com/p/piriti/issues/attachmentText?id=58&aid=580002000&name=Obj.java&token=H3VR7g2Mkbdgm-YHrhtQr62Smjg%3A1351504668855

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.