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

  • Home
  • SEARCH
  • 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 7907341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:23:09+00:00 2026-06-03T11:23:09+00:00

In my Jersey project, I am using MOXy to marshal to/from JSON. One of

  • 0

In my Jersey project, I am using MOXy to marshal to/from JSON. One of the classes I want to to marshal is an array of strings that could be empty.

class Data
{
   @XmlElement(nillable = true) public String[] array;
}

In the case where the array is empty, I would like the output to be:

{ 
   "array" : []
}

however it looks like MOXy is filtering out empty arrays from the output. How can I get it to include empty arrays in the output?

I was thinking about adding JSONConfiguration.mapped().array(“array”).build() to the MOXy provider constructor, but this doesn’t seem to make a difference (and I’m not even sure that it’s the correct solution).

  • 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-03T11:23:10+00:00Added an answer on June 3, 2026 at 11:23 am

    Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.

    ORIGINAL ANSWER

    The following enhancement request has been entered. You can use the link below to track our progress on this issue.

    • http://bugs.eclipse.org/378894

    UPDATE

    Starting with the May 19, 2012 EclipseLink 2.4.0 label you can set the following property to get the behaviour you are looking for.

    marshaller.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, true);
    

    You can download nightly EclipseLink labels from the following location:

    • http://www.eclipse.org/eclipselink/downloads/nightly.php

    Root

    On the following class we have three List properties. Two are of the List objects are empty and one is null. Note that the emptyChoiceList field is mapped with @XmlElements. The @XmlElements annotation states that the possible node names are foo and bar.

    package forum10453441;
    
    import java.util.*;
    import javax.xml.bind.annotation.*;
    
    @XmlType(propOrder={"nullList", "emptyList", "emptyChoiceList"})
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Root {
    
        private List<String> nullList = null;
    
        private List<String> emptyList = new ArrayList<String>();
    
        @XmlElements({
            @XmlElement(name="foo", type=String.class),
            @XmlElement(name="bar", type=String.class)
        })
        private List<String> emptyChoiceList = new ArrayList<String>();
    
    }
    

    Demo

    The following code demonstrates how to specify the MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS property.

    package forum10453441;
    
    import javax.xml.bind.*;
    import org.eclipse.persistence.jaxb.MarshallerProperties;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Root.class);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
            marshaller.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, true);
    
            Root root = new Root();
            marshaller.marshal(root, System.out);
        }
    
    }
    

    Output

    Now in the output the empty lists are marshalled as empty arrays. For the field that was mapped with @XmlElememts the node name that was specified was used in the JSON representation.

    {
       "emptyList" : [ ],
       "foo" : [ ]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Jersey, I want to be able to have a GET request, that would
I have a jersey client that is getting JSON from a source that I
I'm trying to debug a rest/json service that i build using Jersey and Amazon
So I have a project I am converting over from Spring MVC to Jersey
I am implementing simple RESTful webservice using Jersey API. My server project is hosted
I want to realise a restlet client for my jersey service. I know that
I have created a web application using Jersey and Dynamic Web Project of Eclipse.
Jersey offers two classes to interact with annotations on resources: ResourceFilterFactory , one class
I want to use Jersey 1.1 with spring 2.5. The exact thing that i
I am using jersey, and I want to send (in a POST) a list

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.