Possible Duplicate:
What is the difference between Serialization and Marshalling?
什么是java中的编码以及编码和序列化之间有什么区别?
最佳答案
Stackoverflow 上有很多关于此问题的优秀帖子,但如果您想要一个简单的答案,这里是:
它们是相同的,并且这些术语可以互换使用。在Java世界中,两者都被实际使用。
对于JAXB (将对象转换为 XML),使用术语编码。例如,
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
Unmarshaller u = jc.createUnmarshaller();
FooObject obj = (FooObject)u.unmarshal( new File( "foo.xml" ) );
Marshaller m = jc.createMarshaller();
为了将 Java 对象转换为字节,使用术语“序列化”。例如,
import java.io.Serializable;
public class Person implements Serializable
{
private String name;
public Person(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}
所以这主要是语义。
关于java - 编码和序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3511654/