小编edw*_*ong的帖子

JAXB不调用Setter方法

我无法理解我做错了什么.我想使用JAXB解组xml,但我注意到没有调用setter方法.我使用的是Java 1.5.Attribute.java类中的Getters和Setter - 工作正常,但在Configuration.java类中 - Setter方法不调用.你能告诉我我哪里错了吗?

@XmlRootElement(name="configuration")
@XmlAccessorType(XmlAccessType.NONE)
public class Configuration {    
    public List< Configuration> getItems() {
        return new ArrayList<Attribute>(getMap().values());
    }

    @XmlElement(name="attributes")
    public void setItems(List<Attribute> attributes) {
        getMap().clear();
        for (Attribute attribute : attributes) {
            getMap().put(attribute.getName(), attribute);
        }
    }

    private Map<String, Attribute> map;

    public Map<String, Attribute> getMap() {

        if (map == null) {
            map = new HashMap<String, Attribute>();
        }
        return map;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的XML看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <attributes name="some_name" type="calculation" value="select ? from dual" priority="0"/>
</configuration>
Run Code Online (Sandbox Code Playgroud)

java xml jaxb

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

使用层次结构编组抽象类后删除 xsi:type

如果有人帮助我,那就太好了。所以我有一个结构:

<letters> <list> <name>Simon</name> <type>2</type> <passengerName>Johny</passengerName> <passengerSurname>Revelator</passengerSurname> </list> <list> <name>someName</name> <type>4</type> <fileURL>someUrl</fileURL> <specialNotes>specialNotes</specialNotes> </list> </letters>

对于这个结构,我编写了 Java 类,它们对它进行编组和解组:A 类包 com.edhex.testing;

import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso({B.class, C.class})
@XmlType
abstract public class A {
    int type;
    String name;

    @XmlElement
    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @XmlElement
    public String getName() {
        return name;
    }

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

班级信件:

@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Letters {
    List<A> list;

    @XmlElement …
Run Code Online (Sandbox Code Playgroud)

java xml jaxb

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

Corda:合同附件如何在交易中转移?

使用附件页面状态:

附件是通过哈希从事务引用的ZIP / JAR文件,但不包含在事务本身中。

但是,“ API:合同约束”页面指出:

包含状态和合同类以及可选的依赖关系的JAR都附加到事务中。

这里有一个代码片段,显示了如何添加合同约束:

transaction.addOutputState(state, constraint = HashAttachmentConstraint(serviceHub.cordappProvider.getContractAttachmentID(CONTRACT_ID)!!))
Run Code Online (Sandbox Code Playgroud)

但是,在签出HashAttachment代码时,我看不到它包含Contract Jar文件的内部信息。

我的假设是我们不会随交易一起转移合约罐。发生的情况可以描述为:

  1. During Nodes start-up Corda scans all CorDapps and load jars that consists of Contract classes into local Attachment Storage.
  2. Each Output state in the Transaction can have a Contract Constraint.
  3. During the verification stage, verifyConstraints(contractAttachmentsByContract) will be invoked and those constraints (e.g. HashAttachmentConstraint) will be validated against attachments that Node has in its local storage.

Questions:

  1. Does Transaction include the …

corda

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

覆盖方法(早期连接)并放置"null"

大家早上好.我以为我知道覆盖和超载意味着什么,并试图向我的朋友解释.一切都很好,但当我回到家时,我决定写下这个例子.

    public class Car{

    public void say(){
        System.out.println("Dodge");
    }

    public static void main(String[] args){
        Car c = new Dodge();
        new Car().print(c);
    }
    public void print(Car t){
        System.out.println("Car");
    }
    public void print(Dodge b){
        System.out.println("Dodge");
    }
}

class Dodge extends Car{
    public void say(){
        System.out.println("Dodge");
    }
}
Run Code Online (Sandbox Code Playgroud)

很明显,如果我们运行这段代码:"Car"将是输出.因为编译器会找到采用格式对象Car的方法.但是如果我们改变这样的主要方法呢:

public static void main(String[] args){
    new Car().print(null);
}
Run Code Online (Sandbox Code Playgroud)

输出将是:"道奇",我无法弄清楚为什么?可以smb解释一下吗?

PS我试过写过这段代码:

public class Car{

public void say(){
    System.out.println("Dodge");
}

public static void main(String[] args){
    new Car().print(null);
}
public void print(BigInteger t){
    System.out.println("Car");
}
public void …
Run Code Online (Sandbox Code Playgroud)

java overriding

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

标签 统计

java ×3

jaxb ×2

xml ×2

corda ×1

overriding ×1