How to have an optional element in XStream (XML -> Java Object) - java

I am serializing an XML document into a Java Object. There are some elements which I want to be optional. If provided in the XML, then it will end up adding extra functionality. But, if the element is missing from the XML, that's fine too -- don't throw an error because of it.
In the latest release of XStream, it noted that there is a converter now for Optional; thought, I am not sure how to implement that.
I looked to see if there was any documentation on this, but I struggled to find anything. I looked on StackOverflow for any answers, but there were none that I found that solved my problem. I also searched the GitHub issues for examples of how to do it.

Related

swagger codegen keyword additions

I have to maintain a project that uses Swagger to codegen the api interface. Looking at the model.mustache, I see this:
{{#models}}
{{#model}}{{#description}}
/**
* {{description}}
**/{{/description}}
and a bunch of other keywords like enum, defaultValue, vars, package, etc. Where do these come from? I've been scouring the internet trying to find swagger documentation on this but I cannot find anything. Lots of the links that refer to swagger info on github return 404 pages. In the end, what I want to be able to do is to have a property exist in my actual .json file that swagger is using to generate the interfaces and models to conditionally generate code. I saw that there is the
{{#property}}{{/property}}
{{^property}}{{/property}}
notation for if/else statements, but it doesn’t work on any property of my own .json. For example, in my json I have an id field. So if I wanted to do a contrived example
{{#id}}System.out.println(“test test”);{{/id}}
won’t work because swagger does not recognize the id tag. So my question is, can I add these tags?
there are lots of tools to help out. If you see broken links, please submit issues to the swagger-codegen project.
As of 2.1.x-M1, swagger-codegen has a very helpful "debug" mode which lets you list all the possible values for your environment. You can invoke it as follows:
java -DdebugModels -jar {path-to}/swagger-codegen-cli.jar generate {opts}
The supported debug flags are:
-DdebugModels: outputs the variables for each model discovered by codegen
-DdebugOperations: outputs the variables for each operation
-DdebugSupportingFiles: shows supporting file data (anything but models or operations)
-DdebugSwagger: shows the parsed swagger representation
I do see that these are missing from the README. Will make sure they get added.

Documentation of spring form path data binding attributes

I've tried any number of searches looking for an actual definition/description of just what is legal as a Spring form path and I cannot find anything. i.e.
<form:select path="What can I put here?">.
The closest I've been able to find is the table on this page:
http://docs.spring.io/spring/docs/2.5.x/reference/validation.html
Table 5.1 gives "examples", but they are only examples.
I really am looking for a definitive explanation of exactly what is legal in a Spring path and also whether any of those are limited to certain versions. I realize this is edging close to asking for favorite off-site resources but I'm looking for the information or links to the official documentation that covers this, not random tutorials, so it should be on topic. I can find plenty of tutorials online but I'm looking for complete reference not a basic introduction.
I'm working on a project using spring-core-2.5.3.jar, I'd really like to find out what is possible in that version although having reference material for more current Spring versions would be good too. I don't know how possible it will be to get an upgrade of Spring done on this project unfortunately.
To be clear - I'm aware that you can access the property String getFoo() using the path "foo". That in some versions of Spring (which?) you can access the first element of String[] getBar() using "bar[0]", etc.
But what are the limitations on this, are there any other things you can do?
Does it support maps and sets?
If it's a complex thing like Map<String,List[Integer]> oof can you do oof["test"][3] as the path?.
Basically the path supports a lot more than just the simple property reading but I can't find anything telling me just what the options and limitations are. Rather than just trying things and seeing what works and hoping I think of everything I'd really like to have a comprehensive list of some kind showing me just what my options are.
Its the reference to the comand object property you want to reference by that field
so if its MyCommand.getCheddar()
you write "cheddar" in path. This is part of spring-mvc, not core spring. It uses the standard convention

Framework to validate XML order against XSD

I am looking for a Java framework which can validate order of elements in XML against XSD. I have already tried JDK 5's javax.xml.Validate and popular article http://www.ibm.com/developerworks/xml/library/x-javaxmlvalidapi/index.html
But none of it gave me specific result.These implementation one way or another told me that xml is invalid but could not provide me specific error description.
maybe take a look at this page:
https://www.java-tips.org/java-ee-tips-100042/175-java-architecture-for-xml-binding/1833-what-is-new-in-jaxb-20.html
You can do nearly everything in XML with the JAXB

JSON parser for J2ME

I need a basic JSON parser that works with J2ME / CLDC 1.1.
A Google search returns tons of answers on this (some even on stackoverflow), but it appears that all point to libraries and solutions that are no longer available (for example, lots point to an implementation that is supposed to be on the json.org site, but at least I can't find anything that isn't J2SE only there).
My best hope so far is the source linked here: https://meapplicationdevelopers.dev.java.net/mobileajax.html, but from that one I can't even find a straight forward way to download the code.
Given the mature state of Java in all other aspects, surely there must be somewhere I can get a pre-compiled JAR to use for parsing JSON from J2ME?
After getting the accepted answer from ZZ Coder, I downloaded the linked code and built a JAR from it.
So in case you need a compiled JSON serializer/deserializer for J2ME/CLDC, you can find the source code here: https://bitbucket.org/liedman/json-me
There is an org.json parser for J2ME but I can't remember the original link. You can get the source code here,
http://grt192.googlecode.com/svn/trunk/CannonBot/src/org/json/me/

Using XMLBeans on Android

I was just wondering if anyone had any success in getting XMLBeans (or any other generator) to work on android. It would be very nice if I could use it because I have a very large schema that I would rather not write all the classes by hand.
I had asked about this on the android developers mailing list, but no one responded. This tells me that either they don't care, or no one feels like telling me its not possible.
If anyone knows of anything else like XMLBeans that works for android, please let me know. It would be very helpful.
Thanks,
Robbie
If you're looking to do class generation and DOM parsing, XMLBeans is probably pretty heavy-weight for a mobile device running android. All of the code generated by XMLBeans makes synchronized calls into an underlying data store that I've seen as a hot spot several times when profiling.
I can't suggest any alternatives, but I would be wary of using this even if you could get it to work, because of the afore mentioned performance issue.
You can use Castor . Just be sure, in Android 2.1, not to use default android SAXParser. You'll get namespace errors. You do this by defining the parser to be, for example, Xerces (and the you add the required JARS), in core.properties .
In android 2.2 it may be ok.
Note that if you create an xmlcontext for the unmarsheler with xerces, it still won't work, as the mapping itself would be parsed with android's SAX. It must be done at core (top level properties file) so that even the mapping is parsed by xerces.
finally - performance is as slow as you can expect... :(
Good luck
SM
I got JAXB working on Android.

Categories