编组和序列化

发布于 2024-09-15 09:36:01 字数 235 浏览 1 评论 0原文

可能的重复:
序列化和编组之间有什么区别?

什么是编组在java中,编组和序列化有什么区别?

Possible Duplicate:
What is the difference between Serialization and Marshalling?

what is marshalling in java and what is the difference between marshalling and serialization?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请止步禁区 2024-09-22 09:36:01

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;
   }
}

所以这主要是语义。

There are many excellent posts on Stackoverflow on this, but if you want a simple answer here it is:

They're the same, and the terms are used interchangeably. In the Java world, both are actually used.

For JAXB (converting objects to XML), the term marshalling is used. e.g.,

       JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
       Unmarshaller u = jc.createUnmarshaller();
       FooObject obj = (FooObject)u.unmarshal( new File( "foo.xml" ) );
       Marshaller m = jc.createMarshaller();

For converting Java objects to bytes, the term serializing is used. e.g.,

import java.io.Serializable;
public class Person implements Serializable
{
   private String name;

   public Person(String name)
   {
      this.name = name;
   }
   public String getName()
   {
      return name;
   }
}

So it's mostly semantics.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文