小编Liv*_* T.的帖子

Gson:如何在没有注释的情况下从序列化中排除特定字段

我正在努力学习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像一个字段名称firstNamecountry,但我似乎无法管理排除像某些领域的性能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)

java serialization json gson

404
推荐指数
12
解决办法
31万
查看次数

窗口调整角度的信息

我刚刚发布这个小提琴,认为它可能对像我这样的人有帮助.它显示了如何将普通的javascript传递给角度范围.在这种情况下,范围获取窗口内部化信息.

http://jsfiddle.net/spacm/HeMZP/

为了个人使用,我将传递给角度范围这些信息:

  • 宽度和高度
  • 方向/方向变化
  • iframe检测
  • OS检测

使用navigator.platform变量

function isInIFrame(){
    return window.location !== window.parent.location;
}

function updateMediaInfoWH() {
    if((typeof(mediaInfo.inIFrame)!='undefined') && (!mediaInfo.inIFrame)) {
        mediaInfo.width = innerWidth;
        mediaInfo.height = innerHeight;
        updateMediaInfoOrientation();
    }
    tellAngular();
}

function tellAngular() {
    console.log("tellAngular");
    var domElt = document.getElementById('mainContainer');
    scope = angular.element(domElt).scope();
    console.log(scope);
    scope.$apply(function(){
        scope.mediaInfo = mediaInfo;
        scope.info = mediaInfo.width;
    });
}
Run Code Online (Sandbox Code Playgroud)

欢迎任何评论.

javascript window-resize angularjs

4
推荐指数
1
解决办法
5330
查看次数

两个Java字符串表示它们不相等

我有两个arraylists,一个包含字符串,另一个包含具有String数据成员的类.目标是通过第二个arraylist中的对象进行递归,并找到哪个对象的字符串数据成员等于第一个arraylist中的字符串值.

现在我明白你不能使用==运算符来比较字符串,所以我最初使用了equals方法,现在我已经尝试了contentEquals方法,但无论我选择哪种方法,字符串总是被归类为相等 - 即使他们不是.因此,每当我运行下面的代码时,无论字符串是否实际相等,"if"语句在第一次调用时总是返回true.

Iterator stringListIter = stringList.iterator();
Iterator objectListIter = objectList.iterator();
while (stringListIter.hasNext())
{
    String currentString = (String) stringListIter.next();
    while (objectListIter.hasNext())
    {
        MyObject currentObject = (MyObject) objectListIter.next();
        String objectString = currentObject.getString();
        if (objectString.contentEquals(currentString));
        {
            //Do something here.....
            break;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.我觉得它可能是相当简单的东西,但我只是看不到它.

java string arraylist

0
推荐指数
1
解决办法
226
查看次数