我正在努力学习Gson,而我正在努力进行场上排斥.这是我的课程
public class Student {
private Long id;
private String firstName = "Philip";
private String middleName = "J.";
private String initials = "P.F";
private String lastName = "Fry";
private Country country;
private Country countryOfBirth;
}
public class Country {
private Long id;
private String name;
private Object other;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用GsonBuilder并添加ExclusionStrategy像一个字段名称firstName或country,但我似乎无法管理排除像某些领域的性能country.name.
使用该方法public boolean shouldSkipField(FieldAttributes fa),FieldAttributes不包含足够的信息来匹配具有过滤器的字段country.name.
对于这个问题的解决方案,我将不胜感激.
PS:我想避免注释,因为我想对此进行改进并使用RegEx来过滤字段.
谢谢
编辑:我试图看看是否可以模拟Struts2 JSON插件的行为
使用Gson
<interceptor-ref name="json">
<param name="enableSMD">true</param>
<param name="excludeProperties">
login.password, …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用Android Retrofit发送JSON的Android应用程序(它在JSON中转换POJO类).它工作正常,但我需要忽略从POJO类发送JSON一个元素.
有谁知道任何Android Retrofit注释?
例
POJO课程:
public class sendingPojo
{
long id;
String text1;
String text2;//--> I want to ignore that in the JSON
getId(){return id;}
setId(long id){
this.id = id;
}
getText1(){return text1;}
setText1(String text1){
this.text1 = text1;
}
getText2(){return text2;}
setText2(String text2){
this.text2 = text2;
}
}
Run Code Online (Sandbox Code Playgroud)
接口发件人ApiClass
public interface SvcApi {
@POST(SENDINGPOJO_SVC_PATH)
public sendingPojo addsendingPojo(@Body sendingPojo sp);
}
Run Code Online (Sandbox Code Playgroud)
知道如何忽略text2吗?
我有一个与java中修饰符transient之前的关键字使用相关的问题private.
变量声明:
transient private ResourceBundle pageResourceBundle;
Run Code Online (Sandbox Code Playgroud)
我的班级看起来像这样:
public class LoginViewModel extends AbstractViewModel {
transient private ResourceBundle pageResourceBundle;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
initializeLoginValues();
boolean timeout = BooleanUtils.toBoolean(getHttpServletRequest().getParameter("timeout"));
if (timeout) {
Messagebox.show(pageResourceBundle.getText("MSG_SESSION_HAS_EXPIRED_PLEASE_LOGIN"), pageResourceBundle.getText("LABEL_ALERT"),
Messagebox.OK, Messagebox.ERROR);
}
view.getPage().setTitle(CsdcLicence.get().getApplicationName());
}
Run Code Online (Sandbox Code Playgroud)
我有一些问题.
1.为什么transient在私有变量之前使用关键字?
2.使用此关键字的目的是什么?