小编jty*_*ler的帖子

Jackson XML Annotations:带有属性的String元素

我似乎无法找到制作Pojo的方法使用jackson-xml注释生成xml,如下所示:

<Root>
    <Element1 ns="xxx">
        <Element2 ns="yyy">A String</Element2>
    </Element1>
</Root>
Run Code Online (Sandbox Code Playgroud)

我似乎最接近的是:

根POJO:

public class Root {
    @JacksonXmlProperty(localName = "Element1")
    private Element1 element1;

    public String getElement1() {
        return element1;
    }

    public void setElement1(String element1) {
        this.element1 = element1;
    }
}
Run Code Online (Sandbox Code Playgroud)

Element1 POJO:

public class Element1 {
    @JacksonXmlProperty(isAttribute = true)
    private String ns = "xxx";
    @JacksonXmlProperty(localName = "Element2")
    private Element2 element2;

    public String getElement2() {
        return element2;
    }

    public void setElement2(String element2) {
        this.element2 = element2;
    }
}
Run Code Online (Sandbox Code Playgroud)

Element2 POJO: …

java xml jackson

24
推荐指数
2
解决办法
2万
查看次数

Jackson XML - 使用命名空间前缀反序列化 XML

我正在使用 Jackson XML 插件 ( https://github.com/FasterXML/jackson-dataformat-xml ),我不确定它是否受支持,但我想知道是否可以同时序列化和反序列化带有命名空间前缀的 XML,如下所示:

<name:Foo>
  <name:Bar>
    <name:x>x</name:x>
    <name:y>y</name:y>
  </name:Bar>
</name:Foo>
Run Code Online (Sandbox Code Playgroud)

我可以使用 Jackson 的插件生成这种类型的 XML,如下所示:

@JacksonXmlProperty(localName="name:Bar")
public Bar getBar() {
    return bar;
}
Run Code Online (Sandbox Code Playgroud)

但是,我找不到配置我的 POJO 以从生成的 XML 反序列化的方法。请参阅以下示例代码:

public class Bar{
    @JacksonXmlProperty(localName="name:x")
    public String x = "x";
    @JacksonXmlProperty(localName="name:y")
    public String y = "y";
}
Run Code Online (Sandbox Code Playgroud)
@JacksonXmlRootElement(localName="name:Foo")
    public class Foo{
        private Bar bar;

        @JacksonXmlProperty(localName="name:Bar")
        public Bar getBar() {
           return bar;
        }

        public void setBar(Bar bar) {
            this.bar = bar;
        }   
}
Run Code Online (Sandbox Code Playgroud)
public class TestDeserialization {

    public static void main(String[] …
Run Code Online (Sandbox Code Playgroud)

java xml jackson

9
推荐指数
2
解决办法
1万
查看次数

基于环境的条件注释

是否可以有条件地应用Java注释?例如,假设我有一个带有注释序列的hibernate映射:

@Id
@Column(name = "TABLE_ID")
@GeneratedValue(strategy = SEQUENCE, generator = "generator")
@SequenceGenerator(name = "generator", sequenceName = "TABLE_SEQ")
public Long getId() {
    return this.Id;
}
Run Code Online (Sandbox Code Playgroud)

是否可以执行以下操作,例如,根据环境变量删除注释?

@Id
@Column(name = "TABLE_ID")
if(env.equals('dev')){
  @GeneratedValue(strategy = SEQUENCE, generator = "generator")
  @SequenceGenerator(name = "generator", sequenceName = "TABLE_SEQ")}
public Long getId() {
    return this.Id;
}
Run Code Online (Sandbox Code Playgroud)

注意:我确实理解在这种情况下可以将*.hbm.xml文件用于不同的环境,但是我想使用注释,因为要维护的文件较少.

java annotations

9
推荐指数
1
解决办法
2663
查看次数

失败在当地运行声纳 - 跑步者

我有一个声纳实例在本地机器上运行localhost:9000,我可以去使用控制台.当我尝试从项目的命令行运行sonar-runner时,我收到500错误:

Exception in thread "main" org.sonar.runner.RunnerException: org.picocontainer.PicoLifecycleException: PicoLifecycleException: method 'public void org.sonar.batch.bootstrap.DatabaseCompatibility.start()', instance 'org.sonar.batch.bootstrap.DatabaseCompatibility@3848110b, org.sonar.api.utils.HttpDownloader$HttpException: Fail to download [http://localhost:9000/api/server]. Response code: 500
    at org.sonar.runner.Runner.delegateExecution(Runner.java:288)
    at org.sonar.runner.Runner.execute(Runner.java:151)
    at org.sonar.runner.Main.execute(Main.java:84)
    at org.sonar.runner.Main.main(Main.java:56)
Caused by: org.picocontainer.PicoLifecycleException: PicoLifecycleException: method 'public void org.sonar.batch.bootstrap.DatabaseCompatibility.start()', instance 'org.sonar.batch.bootstrap.DatabaseCompatibility@3848110b, org.sonar.api.utils.HttpDownloader$HttpException: Fail to download [http://localhost:9000/api/server]. Response code: 500
    at org.picocontainer.monitors.NullComponentMonitor.lifecycleInvocationFailed(NullComponentMonitor.java:77)
...
...
Run Code Online (Sandbox Code Playgroud)

但是当我在浏览器中访问url时,我得到以下xml响应:

<server>
<id>20131007131041</id>
<version>3.4.1</version>
<status>UP</status>
</server>
Run Code Online (Sandbox Code Playgroud)

我不知道从哪里开始.有什么建议?

sonar-runner sonarqube

7
推荐指数
1
解决办法
2845
查看次数

javac无视@SuppressWarnings("全部")

我目前有一个Enum,它有一个构造函数,可以取null并包含以下SuppressWarning批注:

@SuppressWarnings("all")
public enum TheEnum {
...
AN_ENUM_VALUE(null),
...
...
private TheEnum(TheEnum ... args) {
    if (args != null){
        ...
        ...
    }
...
}
Run Code Online (Sandbox Code Playgroud)

我目前正在使用MyEclipse工作台10.6,它似乎很好地拿起了注释.但是,在开发机器上进行编译时,我会收到与'TheEnum'类相关的警告.

奇怪的是,在项目中,整个地方都有@SuppressWarnings("unchecked"),编译器设法选择这些并忽略它们就好了.

由于遗留问题,我们必须使用JDK 1.5.0_17进行编译,但它看起来应该选择"全部"抑制:

[root@xxx]:/opt/jdk1.5.0_17/bin# ./javac -X
  ...
  -Xlint:{all,deprecation,unchecked,fallthrough,path,serial,finally,-deprecation,-   unchecked,-fallthrough,-path,-serial,-finally}Enable or disable specific warnings
Run Code Online (Sandbox Code Playgroud)

关于我应该看看为什么"全部"被忽略的任何建议?

java annotations compiler-warnings

5
推荐指数
1
解决办法
3598
查看次数

Eclipse Color Theme - 在jsp编辑器中难以阅读javascript

我一直在使用Eclipse颜色主题插件,到目前为止它一直都很棒 - 但是有一个问题/设置我似乎无法弄清楚如何改变 - 当我尝试在jsp页面中编辑javascript时发生 - 当我选择了一个深色主题(在这种情况下是Monokai),Eclipse使用带有亮点的javascript标签突出显示代码(参见附图).

有没有人知道我是否可以在eclipse中更改设置以更改或删除此设置,或者是否甚至可以更改?

难以阅读的亮点

eclipse themes eclipse-plugin

3
推荐指数
1
解决办法
4681
查看次数