我正在使用ObjectDB来存储我的对象。但是我想存储一个没有用@Entity
标签注释的对象,因为这些对象是在我的包之外(在库中)创建的,我不想将整个库克隆到我的项目中,只是为了添加注释。这是我要坚持的课程:
package org.telegram.telegrambots.api.objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.telegram.telegrambots.api.interfaces.BotApiObject;
/**
* @author Ruben Bermudez
* @version 3.0
* This object represents a Telegram user or bot.
*/
public class User implements BotApiObject {
private static final String ID_FIELD = "id";
private static final String FIRSTNAME_FIELD = "first_name";
private static final String ISBOT_FIELD = "is_bot";
private static final String LASTNAME_FIELD = "last_name";
private static final String USERNAME_FIELD = "username";
private static final String LANGUAGECODE_FIELD = "language_code";
@JsonProperty(ID_FIELD)
private Integer id; ///< Unique identifier for this user or bot
@JsonProperty(FIRSTNAME_FIELD)
private String firstName; ///< User‘s or bot’s first name
@JsonProperty(ISBOT_FIELD)
private Boolean isBot; ///< True, if this user is a bot
@JsonProperty(LASTNAME_FIELD)
private String lastName; ///< Optional. User‘s or bot’s last name
@JsonProperty(USERNAME_FIELD)
private String userName; ///< Optional. User‘s or bot’s username
@JsonProperty(LANGUAGECODE_FIELD)
private String languageCode; ///< Optional. IETF language tag of the user's language
public User() {
super();
}
public Integer getId() {
return id;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getUserName() {
return userName;
}
public String getLanguageCode() {
return languageCode;
}
public Boolean getBot() {
return isBot;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", isBot=" + isBot +
", lastName='" + lastName + '\'' +
", userName='" + userName + '\'' +
", languageCode='" + languageCode + '\'' +
'}';
}
}
这就是BotApiObject
类,虽然它没有什么重要的:
package org.telegram.telegrambots.api.interfaces;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
/**
* @author Ruben Bermudez
* @version 1.0
* An object from the Bots API received from Telegram Servers
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public interface BotApiObject extends Serializable {
}
我知道我可以创建这个类的克隆,使用它进行注释@Entity
并使用适配器来转换它们,但这是一种浪费。我想知道是否有更好的方法来持久化/读取/对未注释的类进行任何操作?