DEV Community

sm-a
sm-a

Posted on

1

When I use xstream I get an "No such field java.lang.Class.prices" error. What I must do the get it to work?

message             : No such field java.lang.Class.prices
field               : prices
class               : com.sm.a.domainhosting.domain.PriceList
required-type       : com.sm.a.domainhosting.domain.PriceList
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /priceList/prices
line number         : 3
version             : 1.4.19
-------------------------------
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.handleUnknownField(AbstractReflectionConverter.java:520)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:371)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:74)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:52)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:136)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1421)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1399)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1337)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1326)
    at com.sm.a.domainhosting.GreetingResource.hello(GreetingResource.java:147)
    at com.sm.a.domainhosting.GreetingResource_Subclass.hello$$superforward1(Unknown Source)
    at com.sm.a.domainhosting.GreetingResource_Subclass$$function$$1.apply(Unknown Source)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(Unknown Source)
    at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    at com.sm.a.domainhosting.GreetingResource_Subclass.hello(Unknown Source)
    at com.sm.a.domainhosting.GreetingResource$quarkusrestinvoker$hello_e747664148511e1e5212d3e0f4b40d45c56ab8a1.invoke(Unknown Source)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
    at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:548)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
    at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
    at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:829)
Enter fullscreen mode Exit fullscreen mode

Here my code:

public class BusinessCase {
@XStreamAlias("price")
private Price price;
@XStreamAlias("label")
private String label;
public Price getPrice ()
{
return price;
}
public void setPrice (Price price)
{
this.price = price;
}
public String getLabel ()
{
return label;
}
public void setLabel (String label)
{
this.label = label;
}
@Override
public String toString()
{
return "ClassPojo [price = "+price+", label = "+label+"]";
}
}
public class Comment {
@XStreamAlias("lang")
private String lang;
@XStreamAlias("content")
private String content;
public String getLang ()
{
return lang;
}
public void setLang (String lang)
{
this.lang = lang;
}
public String getContent ()
{
return content;
}
public void setContent (String content)
{
this.content = content;
}
@Override
public String toString()
{
return "ClassPojo [lang = "+lang+", content = "+content+"]";
}
}
view raw Comment.java hosted with ❤ by GitHub
public class Domain {
@XStreamAlias("label")
private String label;
@XStreamAlias("businessCase")
private BusinessCase[] businessCase;
public String getLabel ()
{
return label;
}
public void setLabel (String label)
{
this.label = label;
}
public BusinessCase[] getBusinessCase ()
{
return businessCase;
}
public void setBusinessCase (BusinessCase[] businessCase)
{
this.businessCase = businessCase;
}
@Override
public String toString()
{
return "ClassPojo [label = "+label+", businessCase = "+businessCase+"]";
}
}
view raw Domain.java hosted with ❤ by GitHub
@XStreamAlias("root")
public class DomainPrices {
@XStreamAlias("priceList")
private PriceList priceList;
public PriceList getPriceList ()
{
return priceList;
}
public void setPriceList (PriceList priceList)
{
this.priceList = priceList;
}
@Override
public String toString()
{
return "ClassPojo [priceList = "+priceList+"]";
}
}
[...]
XStream xstream = new XStream();
xstream.processAnnotations(DomainPrices.class);
xstream.processAnnotations(PriceList.class);
xstream.processAnnotations(Prices.class);
xstream.processAnnotations(Domain.class);
xstream.processAnnotations(BusinessCase.class);
xstream.processAnnotations(Price.class);
xstream.processAnnotations(Promos.class);
xstream.processAnnotations(Validity.class);
xstream.processAnnotations(Regular.class);
xstream.processAnnotations(Comment.class);
xstream.allowTypesByWildcard(new String[]{"com.sm.a.domainhosting.**"});
DomainPrices smaData = (DomainPrices)xstream.fromXML(xml, DomainPrices.class);
String smaResult = "leer";
for (Domain smaDataFor : smaData.getPriceList().getPrices().getDomain()) {
System.out.println("DOMAIN: " + smaDataFor.getLabel());
for (BusinessCase smaDataForBusinessCase : smaDataFor.getBusinessCase()) {
System.out.println("Price: " + smaDataForBusinessCase.getPrice().getAmount());
break;
}
}
[...]
view raw Main.java hosted with ❤ by GitHub
public class Price {
@XStreamAlias("amount")
private String amount;
@XStreamAlias("period")
private String period;
@XStreamAlias("vatRate")
private String vatRate;
@XStreamAlias("currency")
private String currency;
@XStreamAlias("validity")
private Validity validity;
@XStreamAlias("tyoe")
private String type;
@XStreamAlias("regular")
private Regular regular;
public String getAmount ()
{
return amount;
}
public void setAmount (String amount)
{
this.amount = amount;
}
public String getPeriod ()
{
return period;
}
public void setPeriod (String period)
{
this.period = period;
}
public String getVatRate ()
{
return vatRate;
}
public void setVatRate (String vatRate)
{
this.vatRate = vatRate;
}
public String getCurrency ()
{
return currency;
}
public void setCurrency (String currency)
{
this.currency = currency;
}
public Validity getValidity ()
{
return validity;
}
public void setValidity (Validity validity)
{
this.validity = validity;
}
public String getType ()
{
return type;
}
public void setType (String type)
{
this.type = type;
}
public Regular getRegular ()
{
return regular;
}
public void setRegular (Regular regular)
{
this.regular = regular;
}
@Override
public String toString()
{
return "ClassPojo [amount = "+amount+", period = "+period+", vatRate = "+vatRate+", currency = "+currency+", validity = "+validity+", type = "+type+", regular = "+regular+"]";
}
}
view raw Price.java hosted with ❤ by GitHub
@XStreamAlias("priceList")
public class PriceList {
@XStreamAlias("generated")
private String generated;
@XStreamAlias("comment")
private Comment[] comment;
@XStreamAlias("prices")
private Prices prices;
@XStreamAlias("promos")
private Promos promos;
@XStreamAlias("customer")
private String customer;
public String getGenerated() {
return generated;
}
public void setGenerated(String generated) {
this.generated = generated;
}
public Comment[] getComment() {
return comment;
}
public void setComment(Comment[] comment) {
this.comment = comment;
}
public Prices getPrices() {
return prices;
}
public void setPrices(Prices prices) {
this.prices = prices;
}
public Promos getPromos() {
return promos;
}
public void setPromos(Promos promos) {
this.promos = promos;
}
public String getCustomer() {
return customer;
}
public void setCustomer(String customer) {
this.customer = customer;
}
@Override
public String toString()
{
return "ClassPojo [generated = "+generated+", comment = "+comment+", prices = "+prices+", promos = "+promos+", customer = "+customer+"]";
}
}
view raw PriceList.java hosted with ❤ by GitHub
@XStreamAlias("prices")
public class Prices {
@XStreamAlias("domain")
private Domain[] domain;
public Domain[] getDomain ()
{
return domain;
}
public void setDomain (Domain[] domain)
{
this.domain = domain;
}
@Override
public String toString()
{
return "ClassPojo [domain = "+domain+"]";
}
}
view raw Prices.java hosted with ❤ by GitHub
public class Promos {
@XStreamAlias("domain")
private Domain[] domain;
public Domain[] getDomain ()
{
return domain;
}
public void setDomain (Domain[] domain)
{
this.domain = domain;
}
@Override
public String toString()
{
return "ClassPojo [domain = "+domain+"]";
}
}
view raw Promos.java hosted with ❤ by GitHub
public class Regular {
@XStreamAlias("amount")
private String amount;
@XStreamAlias("period")
private String period;
@XStreamAlias("vatRate")
private String vatRate;
@XStreamAlias("currency")
private String currency;
@XStreamAlias("type")
private String type;
public String getAmount ()
{
return amount;
}
public void setAmount (String amount)
{
this.amount = amount;
}
public String getPeriod ()
{
return period;
}
public void setPeriod (String period)
{
this.period = period;
}
public String getVatRate ()
{
return vatRate;
}
public void setVatRate (String vatRate)
{
this.vatRate = vatRate;
}
public String getCurrency ()
{
return currency;
}
public void setCurrency (String currency)
{
this.currency = currency;
}
public String getType ()
{
return type;
}
public void setType (String type)
{
this.type = type;
}
@Override
public String toString()
{
return "ClassPojo [amount = "+amount+", period = "+period+", vatRate = "+vatRate+", currency = "+currency+", type = "+type+"]";
}
}
view raw Regular.java hosted with ❤ by GitHub
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<priceList xmlns="urn:com:internet:ns:price_list-1.0" generated="2022-04-24T21:59:57+02:00" customer="1234567892">
<prices>
<domain label="com">
<businessCase label="create">
<price type="NET" vatRate="19.0" currency="EUR" amount="9.52"
period="1y" />
</businessCase>
<businessCase label="renew">
<price type="NET" vatRate="19.0" currency="EUR" amount="9.52"
period="1y" />
</businessCase>
<businessCase label="transfer">
<price type="NET" vatRate="19.0" currency="EUR" amount="9.52"
period="1y" />
</businessCase>
<businessCase label="restore">
<price type="NET" vatRate="19.0" currency="EUR" amount="69.0" />
</businessCase>
<businessCase label="ownerchange">
<price type="NET" vatRate="19.0" currency="EUR" amount="0.0" />
</businessCase>
</domain>
<domain label="de">
<businessCase label="create">
<price type="NET" vatRate="19.0" currency="EUR" amount="4.9"
period="1y" />
</businessCase>
<businessCase label="renew">
<price type="NET" vatRate="19.0" currency="EUR" amount="4.5"
period="1y" />
</businessCase>
<businessCase label="transfer">
<price type="NET" vatRate="19.0" currency="EUR" amount="4.5"
period="1y" />
</businessCase>
<businessCase label="restore">
<price type="NET" vatRate="19.0" currency="EUR" amount="15.0" />
</businessCase>
<businessCase label="ownerchange">
<price type="NET" vatRate="19.0" currency="EUR" amount="0.0" />
</businessCase>
<businessCase label="authinfo">
<price type="NET" vatRate="19.0" currency="EUR" amount="15.0" />
</businessCase>
</domain>
</prices>
<promos>
<domain label="info">
<businessCase label="create">
<price type="NET" vatRate="19.0" currency="EUR" amount="4.4"
period="1y">
<validity from="2022-02-01T00:00:00+01:00"
until="2022-06-30T23:59:59+02:00" />
<regular type="NET" vatRate="19.0" currency="EUR"
amount="16.02" period="1y" />
</price>
</businessCase>
</domain>
<domain label="mobi">
<businessCase label="create">
<price type="NET" vatRate="19.0" currency="EUR" amount="4.4"
period="1y">
<validity from="2022-02-01T00:00:00+01:00"
until="2022-06-30T23:59:59+02:00" />
<regular type="NET" vatRate="19.0" currency="EUR"
amount="26.7" period="1y" />
</price>
</businessCase>
</domain>
</promos>
<comment lang="de">
Alle Preise netto zzgl. MwSt. Alle Angaben ohne Gewähr.
</comment>
<comment lang="en">
All prices are net cash without tax. No responsibility is taken for the
correctness of this information.
</comment>
</priceList>
view raw test.xml hosted with ❤ by GitHub
public class Validity {
@XStreamAlias("from")
private String from;
@XStreamAlias("until")
private String until;
public String getFrom ()
{
return from;
}
public void setFrom (String from)
{
this.from = from;
}
public String getUntil ()
{
return until;
}
public void setUntil (String until)
{
this.until = until;
}
@Override
public String toString()
{
return "ClassPojo [from = "+from+", until = "+until+"]";
}
}
view raw Validity.java hosted with ❤ by GitHub

tags: java, xstream


Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay