Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:29:32+00:00 2026-06-18T10:29:32+00:00

is there a way to serialize a java var (e.g. int) via jackson as

  • 0

is there a way to serialize a java var (e.g. int) via jackson as an xml attribute?
I can not find any spezific jackson or json annotation (@XmlAttribute
@javax.xml.bind.annotation.XmlAttribute) to realize this.

e.g.

public class Point {

    private int x, y, z;

    public Point(final int x, final int y, final int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    @javax.xml.bind.annotation.XmlAttribute
    public int getX() {
        return x;
    }
    ...
}

What I want:

<point x="100" y="100" z="100"/>

but all I got is:

<point>
    <x>100</x>
    <y>100</y>
    <z>100</z>
</point>

Is there a way to get attributes instead of elements?
Thanks for help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:29:33+00:00Added an answer on June 18, 2026 at 10:29 am

    Okay I found a solution.

    It wasn’t necessary to register an AnnotaionIntrospector if you use jackson-dataformat-xml

    File file = new File("PointTest.xml");
    XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.writeValue(file, new Point(100, 100, 100));
    

    The missing TAG was

    @JacksonXmlProperty(isAttribute=true)

    so just change the getter to:

    @JacksonXmlProperty(isAttribute=true)
    public int getX() {
        return x;
    }
    

    and it works fine. Just follow this how to:

    https://github.com/FasterXML/jackson-dataformat-xml

    @JacksonXmlProperty allows specifying XML namespace and local name for
    a property; as well as whether property is to be written as an XML
    element or attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there any way to serialize an expando subclass which can be retrieved with
is there any way how to be able to serialize object in .NET and
Is there any way to persist a java object, thrift serialized, and recover it
Is there a simple way to serialize a single-level structure as a string for
Is there any way to add fields to a DataSet which will be serialized
Is there way that I can read the file from remote server using fopen
Is there a way to convert an ANSI string to UTF using Java. I
It seems my java.util.date variable is being formatted in a way I can't control.
Is there a way to determine the generated serialVersionUID of a serialized Java object?
Does anyone know if there is a straightforward way to serialize a parsed cyberneko

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.