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 4626522
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:25:59+00:00 2026-05-22T03:25:59+00:00

I want to make sure that an xml element-content is unmarshalled in upper case

  • 0

I want to make sure that an xml element-content is unmarshalled in upper case on my object.

public class SZM {

    String field01;
    @XmlElement(name="field01")
    public void setField01(String value) {this.field01 = value.toUpperCase();}
    public String getField01() {return field01;}

but how to do the same thing for every item in a collection? I want that any value read from the xml is capitalized.

@XmlElement
ArrayList<String>collection01;

Thanks in advance,
Agostino

all the class, just in case:

package test.jaxb;

import java.util.ArrayList;
import javax.xml.bind.annotation.*;

@XmlRootElement
public class SZM {
    String field01;
    @XmlElement(name="field01")
    public void setField01(String value) {this.field01 = value.toUpperCase();}
    public String getField01() {return field01;}

    @XmlElement
    ArrayList<String>collection01;

}
  • 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-05-22T03:26:00+00:00Added an answer on May 22, 2026 at 3:26 am

    You can use an XmlAdapter to manipulate the String values:

    StringCaseAdapter

    import javax.xml.bind.annotation.adapters.XmlAdapter;
    
    public class StringCaseAdapter extends XmlAdapter<String, String> {
    
        @Override
        public String unmarshal(String v) throws Exception {
            return v.toUpperCase();
        }
    
        @Override
        public String marshal(String v) throws Exception {
            return v.toLowerCase();
        }
    
    }
    

    SZM

    You reference the XmlAdapter as:

    package test.jaxb;
    
    import java.util.ArrayList;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement
    public class SZM {
        String field01;
    
        @XmlElement(name="field01")
        @XmlJavaTypeAdapter(StringCaseAdapter.class)
        public void setField01(String value) {this.field01 = value;}
        public String getField01() {return field01;}
    
        @XmlElement
        @XmlJavaTypeAdapter(StringCaseAdapter.class)
        ArrayList<String>collection01;
    
    }
    

    input.xml

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <szm>
        <collection01>def</collection01>
        <collection01>ghi</collection01>
        <field01>abc</field01>
    </szm>
    

    Demo

    import java.io.File;
    
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(SZM.class);
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            SZM szm = (SZM) unmarshaller.unmarshal(new File("input.xml"));
    
            System.out.println(szm.getField01());
            for(String item : szm.collection01) {
                System.out.println(item);
            }
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(szm, System.out);
        }
    
    }
    

    Output

    ABC
    DEF
    GHI
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <szm>
        <collection01>def</collection01>
        <collection01>ghi</collection01>
        <field01>abc</field01>
    </szm>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an xml schema, and I want to make sure that the
I want to make sure that a set of functions have the same signature
I want to make sure that if any error occurs during the database processing
Many of my views fetch external resources. I want to make sure that under
I'm troubleshooting a problem with creating Vista shortcuts. I want to make sure that
To make sure that the text in listbox items is not truncated I want
To allow caching a PHP generated file, I want to make sure, that the
I want to make sure a file path set via query string does not
I want make a xslt transformation to xsl-fo but I´m not really sure that
I want to make sure people can't type the name of a PHP script

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.