Проблема с использованием @xmljavatypeadapter для Marshall мгновенный атрибутJAVA

Программисты JAVA общаются здесь
Anonymous
Проблема с использованием @xmljavatypeadapter для Marshall мгновенный атрибут

Сообщение Anonymous »

Я пытаюсь использовать @xmljavatypeadapter для того, чтобы заполучить мой класс tokenvo , даже если у него есть мгновенные атрибуты, которые по умолчанию не используются.import java.io.Serializable;
import java.time.Instant;

import com.vitorbionic.integrationtests.controller.withxml.adapter.InstantAdapter;

import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

@XmlRootElement(name = "TokenVO")
public class TokenVO implements Serializable {
private static final long serialVersionUID = 1L;

private String username;

private Boolean authenticated;

@XmlJavaTypeAdapter(InstantAdapter.class)
private Instant created;

@XmlJavaTypeAdapter(InstantAdapter.class)
private Instant expiration;

private String accessToken;

private String refreshToken;

// Contructors, Getters, Setters, Equals and hashCode
}
< /code>
класс InstantAdapter: < /h2>
import java.time.Instant;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;

public class InstantAdapter extends XmlAdapter {
@Override
public Instant unmarshal(String v) throws Exception {
return Instant.parse(v);
}

@Override
public String marshal(Instant v) throws Exception {
return v.toString();
}
}
< /code>
ошибка: < /h3>
Error: java.lang.RuntimeException: org.glassfish.jaxb.runtime.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions The class has two properties with the same name "created" this problem is related to the following location: at public java.time.Instant com.vitorbionic.integrationtests.vo.TokenVO.getCreated() at com.vitorbionic.integrationtests.vo.TokenVO this problem is related to the following location: at private java.time.Instant com.vitorbionic.integrationtests.vo.TokenVO.created at com.vitorbionic.integrationtests.vo.TokenVO The class has two properties with the same name "expiration" this problem is related to the following location: at public java.time.Instant com.vitorbionic.integrationtests.vo.TokenVO.getExpiration() at com.vitorbionic.integrationtests.vo.TokenVO this problem is related to the following location: at private java.time.Instant com.vitorbionic.integrationtests.vo.TokenVO.expiration at com.vitorbionic.integrationtests.vo.TokenVO


Подробнее здесь: https://stackoverflow.com/questions/794 ... -attribute

Вернуться в «JAVA»