I've made an RESTful api that returns following simple XML:
<!-- language: lang-xml -->
<?xml version="1.0" encoding="utf-8"?>
<GoldPriceArray>
<GoldPrice>
<Date>2020-06-15</Date>
<Price>219.01</Price>
</GoldPrice>
<GoldPrice>
<Date>2020-06-16</Date>
<Price>216.73</Price>
</GoldPrice>
</GoldPriceArray>
I'm trying to unmarchall Date and Price but cannot get into nested elements - my code returns NullPointerException on unmarchaller() method. Here's my code
#XmlAccessorType(XmlAccessType.FIELD)
#XmlRootElement(name = "GoldPriceArray")
public class GoldRates {
private List<GoldRate> goldRateList;
private String goldValue;
public GoldRates() {}
public GoldRates(String goldPrice, List<GoldRate> goldRateList) {
this.goldRateList = goldRateList;
this.goldValue = goldPrice;
}
#XmlElement
public List<GoldRate> getList() {
return goldRateList;
}
public void setList(ArrayList<GoldRate> goldRateList) {
this.goldRateList = goldRateList;
}
#XmlElement
public String getPrice() {
return goldValue;
}
public void setPrice(String goldPrice) {
this.goldValue = goldPrice;}
public class GoldRate {
#XmlElement(name = "Date")
private String dateOfPrice;
#XmlElement(name = "Price")
private String price;
public GoldRate() {
}
public GoldRate(String date, String value) {
this.dateOfPrice = date;
this.price = value;
}
public String getDate() {
return dateOfPrice;
}
public void setDate(String date) {
this.dateOfPrice = date;
}
public String getValue() {
return price;
}
public void setValue(String value) {
this.price = value;
}
#Override
public String toString() {
return "Date: " + dateOfPrice + " value: " + price;
}
}
Unmarchalling method that returns NullPointerException on System.out.println()
public void unmarshaller(String xml) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(GoldRates.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
GoldRates goldRates = (GoldRates) jaxbUnmarshaller.unmarshal(new StringReader(xml));
System.out.println(goldRates.getList().get(0).getValue() + " " + goldRates.getList().get(0).getDate());
} catch (JAXBException e) {
e.printStackTrace();
}
return null;
}
Any hints on this one? I'm really stuck.
Just found solution:
private List<GoldRate> goldRateList
should be named exactly the same as an element of XML that it refers to, so the proper one is:
private List<GoldRate> GoldPrice
Related
I have been trying to convert xml string to Java object.
There is a root tag of TV . There are multiple fields inside this but I want the whole content as one String.
#XmlRootElement(name = "TV")
#XmlAccessorType(XmlAccessType.FIELD)
public class TV {
#XmlElement
public String details;
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
#Override
public String toString() {
return "TV [details=" + details + "]";
}
}
public class XMLtoJavaObject {
public static void main(String[] args) {
String xmlString = "<TV version=\"0.91fn\"><channel><title>Friends</title><link>https://www.imdb.com/title/tt0108778/</link><season>2</season></channel></TV>";
JAXBContext jaxbContext;
try {
jaxbContext = JAXBContext.newInstance(TV.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
TV tv = (TV) jaxbUnmarshaller.unmarshal(new StringReader(xmlString));
System.out.println("TV" + tv);
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
Output:
TV [details=null]
I am not getting whole nested xml as String.
Can somebody help me what I am missing?
Thanks in advance
Try this:
TV class:
#XmlRootElement(name = "TV")
#XmlAccessorType(XmlAccessType.FIELD)
public class TV {
#XmlElement
private Channel channel;
public Channel getChannel() {
return channel;
}
public void setChannel(Channel channel) {
this.channel = channel;
}
#Override
public String toString() {
return "TV [channel=" + channel + "]";
}
}
Channel class:
#XmlAccessorType(XmlAccessType.FIELD)
public class Channel {
#XmlElement
private String title;
private String link;
private String season;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getSeason() {
return season;
}
public void setSeason(String season) {
this.season = season;
}
#Override
public String toString() {
return "Channel [title=" + title + ", link=" + link + ", season=" + season + "]";
}
}
Output:
TVTV [channel=Channel [title=Friends, link=https://www.imdb.com/title/tt0108778/, season=2]]
And now You can get Your details using Java as You want e.g.:
tv.getChannel().getTitle();
Another answser:
TV class:
#XmlRootElement(name = "TV")
#XmlAccessorType(XmlAccessType.FIELD)
public class TV {
#XmlAnyElement
private org.w3c.dom.Element channel;
#Override
public String toString() {
return "TV [channel=" + channel + "]";
}
public org.w3c.dom.Element getChannel() {
return channel;
}
public void setChannel(org.w3c.dom.Element channel) {
this.channel = channel;
}
}
Then You get text content like this:
System.out.println("text: " + tv.getChannel().getTextContent());
Output:
text: Friendshttps://www.imdb.com/title/tt0108778/2
Note that it is all texts just concatenated.
But having an Element You can iterate recursively through all children and print them together with tag names and text values.
Here is a sample recursive method:
channel field name needs to be a Node type:
....
private org.w3c.dom.Node channel;
....
private static String build(Node element) {
final String result;
if (element instanceof Text) {
result = element.getNodeValue();
} else {
final StringBuilder sb = new StringBuilder();
sb.append("<").append(element.getNodeName()).append(">");
for (int i = 0; i < element.getChildNodes().getLength(); i++) {
final Node child = element.getChildNodes().item(i);
sb.append(build(child));
}
sb.append("</").append(element.getNodeName()).append(">");
result = sb.toString();
}
return result;
}
Called like this:
System.out.println(build(tv.getChannel()));
Output:
<channel><title>Friends</title><link>https://www.imdb.com/title/tt0108778/</link><season>2</season></channel>
I'm working at a Method to filter a collection (FileList) of xml-files if a specific xml-tag has an attribute...
In detail... I want to filter all xml-files where the xml-tag has an attribute "is_special", but I've problems to setup my model-classes for the attribute.
At the end I want to store the name of the file and a list of its items, where the value has the attribute is_special="true"
Also I'm using the JAXB Framework with the Moxy extension...
The XML-Structure as followed:
<document>
<id>75C8866AB078DCE541256D16002CF636</id>
<size>806220</size>
<author>xxx</author>
<last_modified>2017.06.12 07:15:41 GMT</last_modified>
<added_to_file>2016.07.05 09:50:44 GMT</added_to_file>
<created>2003.04.28 08:11:06 GMT</created>
<items>
<item>
<name>someName/name>
<type>LNITEMTYPE_DATETIMES</type>
<values>
<value is_special="true"/>
</values>
<last_modified>2003.04.28 08:11:10 GMT</last_modified>
...
</item>
<item>
<name>someName/name>
<type>LNITEMTYPE_TEXT</type>
<values>
<value>SOMETEXT</value>
<value>SOMETEXT</value>
</values>
<last_modified>2003.04.28 08:11:10 GMT</last_modified>
...
</item>
</items>
Therefor I've got 3 Classes for the XML-File...
"XMLDocument.java" implements the list of "Items.java" which implements the list of "Value.java"
XMLDocument.java
#XmlRootElement(name = "notes_document")
public class XMLDocument {
...
private List<Item> items;
...
#XmlElementWrapper(name = "items")
#XmlElement(name = "item")
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
}
item.java
#XmlRootElement(name = "items")
public class Item {
private String name;
private List<String> values;
private boolean valueIsSpecial;
#XmlElement(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#XmlElementWrapper(name = "values")
#XmlElement(name = "value")
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
#XmlPath("value/#is_special")
public boolean getValueIsSpecial() {
return valueIsSpecial;
}
public void setValueIsSpecial(boolean valueIsSpecial) {
this.valueIsSpecial = valueIsSpecial;
}
}
value.java
#XmlRootElement(name = "values")
public class Value {
#XmlElement(name = "value")
private String itemValue;
#XmlPath("value/#is_special")
private boolean isSpecial;
public String getValue() {
return itemValue;
}
public void setValue(String value) {
this.itemValue = value;
}
public boolean getValueIsSpecial() {
return isSpecial;
}
public void setValueIsSpecial(boolean isSpecial) {
this.isSpecial = isSpecial;
}
}
My Method so far...
public void FilterTree_isSpecial() throws JAXBException, FileNotFoundException {
for(String file: FileList) {
if (file.endsWith(".xml") && !file.contains("databaseinfo.xml")) {
JAXBContext context = JAXBContext.newInstance(NotesDocumentMetaFile.class);
Unmarshaller um = context.createUnmarshaller();
NotesDocumentMetaFile docMetaFile = (XMLDocument) um.unmarshal(new FileReader(file));
for (int i = 0; i < docMetaFile.getItems().size(); i++) {
// CHECK IF THE <value> OF THIS ITEM HAS ATTRIBUTE is_special
}
}
}
}
Much text... I hope anyone can give me a solution :/
Actually the xpath in your Item.java needs to be : values/value/#is_special like #XmlPath("values/value/#is_special")
If you want the is_special in your Value.java also your xpath should be :
#is_special like : #XmlPath(#is_special)
Also your Item.java, Value.java needs a little change. You don't need #XmlRootElement, you already had it in your XmlDocument.java
Your Item.java should be :
public class Item
{
private String name;
private String type;
private String lastModified;
private List<Value> values;
private String isSpecial;
#XmlPath("values/value/#is_special")
public String getIsSpecial() {
return isSpecial;
}
public void setIsSpecial(String isSpecial) {
this.isSpecial = isSpecial;
}
#XmlElement(name="type")
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
#XmlElement(name="last_modified")
public String getLastModified() {
return lastModified;
}
public void setLastModified(String lastModified) {
this.lastModified = lastModified;
}
#XmlElement(name="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#XmlElementWrapper(name="values")
#XmlElement(name="value")
public List<Value> getValues() {
return values;
}
public void setValues(List<Value> values) {
this.values = values;
}
}
Your Value.java should be :
public class Value
{
#XmlPath("text()")
private String value;
#XmlPath("#is_special")
private String isSpecial;
public String getIsSpecial() {
return isSpecial;
}
public void setIsSpecial(String isSpecial) {
this.isSpecial = isSpecial;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
Note that to get value and is_special in Value.java, you could use #XmlPath.
Now you can call getIsSpecial() on Item.java to check if it is special.
I need my server to unmarshal xml files. I have implemented the class to do this on my own computer running Java 1.8 and it works perfectly. However when I run the exact same code on the server, which runs Java 1.7, the object is created but I get a null value for the 'domain' element.
My code may not be ideal practice when using JAXB, but as I said on java 1.8 it does exactly what I need it to. Does anybody have an idea as to the cause of this behaviour? Any help would be greatly appreciated.
This is an example xml file which I am trying to unmarshal:
<planning:metadata xmlns:planning="http://planning.com">
<domain id=numeric">
<title xml:lang="en">The numeric formulation</title>
<files_last_modified>2002-06-01T12:00:00</files_last_modified>
<metadata_last_modified>2014-04-02T11:31:17.471631</metadata_last_modified>
<published>2002-06-01T12:00:00</published>
<link>http://ipc.icaps.org/</link>
<requirements>
<typing/>
<fluents/>
</requirements>
<problems>
<problem domain_file="domain.pddl" number="1" problem_file="p01.pddl"/>
<problem domain_file="domain.pddl" number="2" problem_file="p02.pddl"/>
<problem domain_file="domain.pddl" number="3" problem_file="p03.pddl"/>
<problem domain_file="domain.pddl" number="4" problem_file="p04.pddl"/>
<problem domain_file="domain.pddl" number="5" problem_file="p05.pddl"/>
<problem domain_file="domain.pddl" number="6" problem_file="p06.pddl"/>
</problems>
</domain>
</planning:metadata>
This is the java file:
package server;
import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
#XmlRootElement(name="metadata")
public class XmlDomain {
private XmlDomain.Domain domain;
public XmlDomain.Domain getDomain() {
return domain;
}
#XmlElement
public void setDomain(XmlDomain.Domain domain) {
this.domain = domain;
}
public static class Domain {
private String id;
private String title;
private Date filesModifiedDate;
private Date metaModifiedDate;
private Date publishedDate;
private String link;
private Requirements requirements;
private Problems problems;
public String getId() {
return id;
}
#XmlAttribute
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
#XmlElement
public void setTitle(String title) {
this.title = title;
}
public Date getFiles_last_modified() {
return filesModifiedDate;
}
#XmlElement
public void setFiles_last_modified(Date date) {
filesModifiedDate = date;
}
public Date getMetadata_last_modified() {
return metaModifiedDate;
}
#XmlElement
public void setMetadata_last_modified(Date date) {
metaModifiedDate = date;
}
public Date getPublished() {
return publishedDate;
}
#XmlElement
public void setPublished(Date date) {
publishedDate = date;
}
public String getLink() {
return link;
}
#XmlElement
public void setLink(String link) {
this.link = link;
}
public Requirements getRequirements() {
return requirements;
}
#XmlElement
public void setRequirements(Requirements requirements) {
this.requirements = requirements;
}
public Problems getProblems() {
return problems;
}
#XmlElement
public void setProblems(Problems problems) {
this.problems = problems;
}
public static class Requirements {
// Strings representing domain requirements
private String strips = null;
private String typing = null;
private String durative = null; // durative-actions
private String fluents = null;
private String timed = null; // time-initial-literal
private String equality = null;
private String inequalities = null; // duration_inequalities
public String getStrips() {
return strips;
}
#XmlElement(name = "strips")
public void setStrips(String strips) {
this.strips = strips;
}
public String getTyping() {
return typing;
}
#XmlElement(name = "typing")
public void setTyping(String typing) {
this.typing = typing;
}
public String getDurative() {
return durative;
}
#XmlElement(name = "durative-actions")
public void setDurative(String durative) {
this.durative = durative;
}
public String getFluents() {
return fluents;
}
#XmlElement(name = "fluents")
public void setFluents(String fluents) {
this.fluents = fluents;
}
public String getTimed() {
return timed;
}
#XmlElement(name = "timed-initial-literals")
public void setTimed(String timed) {
this.timed = timed;
}
public String getEquality() {
return equality;
}
#XmlElement(name = "equality")
public void setEquality(String equality) {
this.equality = equality;
}
public String getInequalities() {
return inequalities;
}
#XmlElement(name = "duration_inequalities")
public void setInequalities(String inequalities) {
this.inequalities = inequalities;
}
}
public static class Problems {
private ArrayList<Problem> problems;
public ArrayList<Problem> getProblem() {
return problems;
}
public void setProblem(ArrayList<Problem> problems) {
this.problems = problems;
}
public static class Problem {
private String domainFile;
private int number;
private String problemFile;
public String getDomain_file() {
return domainFile;
}
#XmlAttribute(name = "domain_file")
public void setDomain_file(String domainFile) {
this.domainFile = domainFile;
}
public int getNumber() {
return number;
}
#XmlAttribute
public void setNumber(int number) {
this.number = number;
}
public String getProblem_file() {
return problemFile;
}
#XmlAttribute(name = "problem_file")
public void setProblem_file(String problemFile) {
this.problemFile = problemFile;
}
public void addResult(Planner planner, double result) {
resultMap.put(planner, result);
}
public double getResult(Planner planner) {
return resultMap.get(planner);
}
public HashMap<Planner, Double> getResultMap() {
return resultMap;
}
}
}
}
}
And the package file:
#XmlSchema(
namespace = "http://planning.com",
elementFormDefault = XmlNsForm.QUALIFIED)
package server;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
Your XML is incorrect according to your schema as defined by your java objects. Everything in your schema is under the http://planning.com namespace but in your XML the only element defined in that namespace is metadata. You need either:
Set http://planning.com to the default namespace.
<metadata xmlns="http://planning.com">
<domain id=numeric">
...
Use the prefix on all the elements
<planning:metadata xmlns:planning="http://planning.com">
<planning:domain id=numeric">
...
Alternativly if the XML can be assumed to be correct but your Java classes are incorrect. In this case just remove the #XmlSchema annotation from your package-info.java and make your Java read:
#XmlRootElement(name="metadata", namespace="http://planning.com")
public class XmlDomain {
...
You dont really have a question in your post as a commentered mentioned so I am unsure if your asking why this works in 1.8 and not in 1.7 and are aware that the XML is incorrect or just didnt know you have some bad XML.
As to why this works in 1.8 is still a mystery to me. I will do a little bit more poking at it and try to find out why out of my own curiosity.
I have an xml input as below
<Confirmations>
<SystemConf>
<SysCnf>
<MessageId>1</MessageId>
</SysCnf>
<SysCnf>
<MessageId>2</MessageId>
</SysCnf>
</SystemConf>
</Confirmations>
and these are my classes
#XmlAccessorType(XmlAccessType.FIELD)
#XmlRootElement(name = "Confirmations")
public class Confirmations
{
#XmlElementWrapper(name = "SystemConf")
#XmlElement(name = "SysCnf")
private List<SystemConfirmation> systemConfirmations = null;
public List<SystemConfirmation> getSystemConfirmations()
{
return systemConfirmations;
}
public void setSystemConfirmations(List<SystemConfirmation> systemConfirmations)
{
this.systemConfirmations = systemConfirmations;
}
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "SysCnf")
public class SystemConfirmation
{
#XmlElement(name = "MessageId")
private String messageId;
public void setMessageId(String messageId)
{
this.messageId = messageId;
}
public String getMessageId()
{
return messageId;
}
#XmlAnyElement(value = SysConfXmlStringHandler.class)
private String xml;
public String getXml()
{
return xml;
}
}
public class SysConfXmlStringHandler implements DomHandler<String, StreamResult>
{
private static final String SYSCONF_START_TAG = "<SycCnf>";
private static final String SYSCONF_END_TAG = "</SysCnf>";
private StringWriter xmlWriter = new StringWriter();
#Override
public StreamResult createUnmarshaller(ValidationEventHandler errorHandler)
{
return new StreamResult(xmlWriter);
}
#Override
public String getElement(StreamResult rt)
{
String xml = rt.getWriter().toString();
System.out.println(xml);
int beginIndex = xml.indexOf(SYSCONF_START_TAG) + SYSCONF_START_TAG.length();
int endIndex = xml.indexOf(SYSCONF_END_TAG);
return xml.substring(beginIndex, endIndex);
}
#Override
public Source marshal(String n, ValidationEventHandler errorHandler)
{
try
{
String xml = SYSCONF_START_TAG + n.trim() + SYSCONF_END_TAG;
StringReader xmlReader = new StringReader(xml);
return new StreamSource(xmlReader);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
Question
In the xml field of the SystemConfirmation class I want the whole xml of that particular SystemConfirmation block xmml element, which would be below
<SysCnf>
<MessageId>1</MessageId>
</SysCnf>
Does anyone know how to achieve this? I tried the above code but I was only getting MessageId block in the xml and if I add multiple fields in SystemConfirmation than I only get the first one.
I want to use javax.ws.rs.core.Response to send and receive an Card entity object. But I don't know how to convert the contents back in to a Card object.
My testCreate() method should execute the create(Card card) method, receive back the json and convert it in to a card object. But I somehow always get type mismatches or it says that the getEntity() method can't be executed like this: response.getEntity(Card.class).
Does anybody know how I have to handle the response correctly so that I can convert the returned json entity in to a Card object again?
Here my CardResource method:
#POST
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response create(Card card) {
Card c = dao.create(card);
if(c.equals(null)) {
return Response.status(Status.BAD_REQUEST).entity("Create failed!").build();
}
return Response.status(Status.OK)
.entity(c)
.type(MediaType.APPLICATION_JSON)
.build();
}
And here my CardResourceTests class
#Test
public void testCreate() {
boolean thrown = false;
CardResource resource = new CardResource();
Card c = new Card(1, "Cardname", "12345678", 1, 1,
"cardname.jpg", new Date(), new Date());
try {
Response result = resource.create(c);
System.out.println(result.getEntity(Card.class)); // not working!!!
if(result.getStatus() != 200) {
thrown = true;
}
} catch(Exception e) {
e.printStackTrace();
thrown = true;
}
assertEquals("Result", false, thrown);
}
And here my Card.class
#XmlRootElement
#PersistenceCapable(detachable="true")
public class Card {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
#Persistent
private Integer id;
#Persistent
private String name;
#Persistent
private String code;
#Persistent
private Integer cardProviderId;
#Persistent
private Integer codeTypeId;
#Persistent
private String picturePath;
#Persistent
private Boolean valid;
#Persistent
private Date mobCreationDate;
#Persistent
private Date mobModificationDate;
#Persistent
private Date creationDate;
#Persistent
private Date modificationDate;
public Card() {
this.setId(null);
this.setName(null);
this.setCode(null);
this.setCardProviderId(null);
this.setCodeTypeId(null);
this.setPicturePath(null);
this.setMobCreationDate(null);
this.setMobModificationDate(null);
this.setCreationDate(null);
this.setModificationDate(null);
}
public Card(Integer id, String name, String code, Integer cardProviderId,
Integer codeTypeId, String picturePath,
Date mobCreationDate, Date mobModificationDate) {
this.setId(id);
this.setName(name);
this.setCode(code);
this.setCardProviderId(cardProviderId);
this.setCodeTypeId(codeTypeId);
this.setPicturePath(picturePath);
this.setMobCreationDate(mobCreationDate);
this.setMobModificationDate(mobModificationDate);
this.setCreationDate(new Date());
this.setModificationDate(new Date());
}
public Key getKey() {
return key;
}
public void setKey(Key key) {
this.key = key;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public Integer getCardProviderId() {
return cardProviderId;
}
public void setCardProviderId(Integer cardProviderId) {
this.cardProviderId = cardProviderId;
}
public void setCode(String code) {
this.code = code;
}
public Integer getCodeTypeId() {
return codeTypeId;
}
public void setCodeTypeId(Integer codeTypeId) {
this.codeTypeId = codeTypeId;
}
public String getPicturePath() {
return picturePath;
}
public void setPicturePath(String picturePath) {
this.picturePath = picturePath;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getModificationDate() {
return modificationDate;
}
public void setModificationDate(Date modificationDate) {
this.modificationDate = modificationDate;
}
public Date getMobCreationDate() {
return mobCreationDate;
}
public void setMobCreationDate(Date mobCreationDate) {
this.mobCreationDate = mobCreationDate;
}
public Date getMobModificationDate() {
return mobModificationDate;
}
public void setMobModificationDate(Date mobModificationDate) {
this.mobModificationDate = mobModificationDate;
}
public Boolean getValid() {
return valid;
}
public void setValid(Boolean valid) {
this.valid = valid;
}
}
And here my CardDAO class
public class CardDAO {
private final static Logger logger = Logger.getLogger(CardDAO.class.getName());
public Card create(Card card) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Card c = new Card(card.getId(), card.getName(), card.getCode(),
card.getCardProviderId(), card.getCodeTypeId(), card.getPicturePath(),
new Date(), new Date());
try {
pm.makePersistent(c);
} catch(Exception e) {
logger.severe("Create failed: " + e.getMessage());
return null;
} finally {
pm.close();
}
return c;
}
}
Is your Card class using #XmlRootElement and #XmlElement annotations to enable JAXB mapping JSON to/from POJO?
See example:
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class Book {
#XmlElement(name = "id")
String id;
//...
I am not sure that it is correct to call the annotated web-service method just like a simple method with params. Try to remove all annotations from your CardResource class and invoke this method simply like a class method.