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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:49:39+00:00 2026-06-10T09:49:39+00:00

I am writing a program in Java in which I need to edit a

  • 0

I am writing a program in Java in which I need to edit a JSON input and then resubmit it via a POST to a different system. In my code I use a HashMap that has a key:value pair in which I update a JSONArray to be the new video type. The code appears to work fine but my code outputs a different order and and I am not sure why.

When I process the code with my Java code the JSON the output looks like this:

    {
    "TransformType": {
        "encodeOptions": [
            {
                "types": [
                    "MPEG"
                ],
                "title": "Convert to MPEG"
            }
        ],
        "processType": "encode"
    }
}

The output that system is expecting looks like this:

{
    "TransformType": {
        "processType": "encode",
        "encodeOptions": [
            {
                "types": [
                    "MPEG"
                ],
                "title": "Convert to MPEG"
            }
        ]
    }
}

My code is very simple:

HashMap<String,String> newTypesMap = new HashMap<String,String>();


    if (TransformTypeObj.has("encodeOptions")) {

        JSONArray encodingOptionsArr = TransformTypeObj.getJSONArray("encodeOptions");

        for( int i = 0; i < encodingOptionsArr.length(); i++ ) {

             JSONObject encodeOptObj = encodeOptionsArray.getJSONObject(i); 
             JSONArray typesArr = encodeOptObj.getJSONArray("types");

             for (int h = 0; h < typesArr.length(); h++) {
                    String oldtype = typesArr.getString(h).toString();
                    String newType = newTypesMap.get(oldtype);
                    typesArr.put(h, newType);
            }
         } 
    }

I cannot edit or see into this third party system but apparently order is important. I edited my Java output into the ‘correct’ format and did a manual post and the system accepts it. If I attempt to use my java code output I get an error saying:

Java.lang.RuntimeException: com.jacksonmedia.data.api.marshalling.MarshallingException: array element type mismatch

Which I assume has something to do with the order of the objects. How can I make the ‘processType’ JSONString be the first element in the TransformType object??

  • 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-10T09:49:41+00:00Added an answer on June 10, 2026 at 9:49 am

    Instead of HashMap use LinkedHashMap which preserves the insertion order.

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

Sidebar

Related Questions

I am writing a java program which would act upon the input which would
I am writing a Java program which automatically plugs information into a website, which
I m writing a program which involves converting java.util.Date to java.sql.Date... I've done it
I'm writing a DLL which a java program uses to call the WinAPI in
I am writing a java program which will create a database LocalStations where it
I am writing a program in Java which tracks data about baseball cards. I
I'm writing a program in which I need to play a song from storage.
I am writing a Java program and I need to set a temporary classpath
For a uni assignment I'm writing a java program which needs to save and
I am writing a small program in java which will draw a path on

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.