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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:57:38+00:00 2026-05-23T22:57:38+00:00

I have to write a proxy client in Java to connect to JSON WebService.

  • 0

I have to write a proxy client in Java to connect to JSON WebService. I have only textual description of WebService methods and types. For instance the result of one method is

Params {
byte[] challenge;
byte[] proff;
}

If I create a class Params in Java with both fields as byte[], jackson mapper treats them as binary arrays and encodes as following example

{"id":2,"method":"Authenticate","params":["bSwY+kKRO7sIJNZFG/L3dK2ke1kIDwzyK5n717MyBG1pnRhjqSF0kRMAyEqLYKA6VBwujaR8K/wr98+G1Av9vQ12soFi+3DViPN4YDguqF0=","2iNJ5UEK3eVxFTEUHMN04QM8WtNrwGSIu1hKVXFMVvQ="]}

The WebService exptects those parameters in a form of comma separated non negative byte values like

[truncated] {"id":2,"method":"Authenticate","params":[[114,109,104,101,70,88,16,32,102,17,117,3,105,104,112,4,39,103,11,54,90,106,90,69,26,20,5,10,121,52,108,64,106,102,52,124,87,8,21,29,28,119,110,70,122,33,105, ...............

I concluded that Jackson mapper uses some kind of automatic Java type recognition and chooses the corresponding JSON type. Is there a way to control it and ie change the type the serializer should use for particular Java type serialization? Where is description and mapping between Java and JSON types?

Regards

  • 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-23T22:57:40+00:00Added an answer on May 23, 2026 at 10:57 pm

    Jackson is representing the byte[] as a base 64 encoded string.

    You’ll need to implement a custom serializer, to manually iterate through the byte[] and generate the JSON array of integer values.


    That didn’t work out quite as I expected it should.

    import java.io.IOException;
    
    import org.codehaus.jackson.JsonGenerator;
    import org.codehaus.jackson.JsonProcessingException;
    import org.codehaus.jackson.Version;
    import org.codehaus.jackson.map.JsonSerializer;
    import org.codehaus.jackson.map.ObjectMapper;
    import org.codehaus.jackson.map.SerializerProvider;
    import org.codehaus.jackson.map.module.SimpleModule;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        ObjectMapper mapper = new ObjectMapper();
        System.out.println(mapper.writeValueAsString(new Bar()));
        // output: {"bytes":"AQIDBAUGBwgJCgsMDQ4PEA=="}
    
        SimpleModule module = new SimpleModule("byte[] as integers", Version.unknownVersion());
        module.addSerializer(byte[].class, new ByteArrayAsIntegersSerializer());
        mapper = new ObjectMapper().withModule(module);
        System.out.println(mapper.writeValueAsString(new Bar()));
        // output: {"bytes":"AQIDBAUGBwgJCgsMDQ4PEA=="}
        // ByteArrayAsIntegersSerializer was not used!
    
        module = new SimpleModule("byte[] as integers 2", Version.unknownVersion());
        module.addSerializer(Bar.class, new BarSerializer());
        mapper = new ObjectMapper().withModule(module);
        System.out.println(mapper.writeValueAsString(new Bar()));
        // output: {"bytes":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]}
      }
    }
    
    class Bar
    {
      public byte[] bytes = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
    }
    
    class BarSerializer extends JsonSerializer<Bar>
    {
      @Override
      public void serialize(Bar value, JsonGenerator jgen, SerializerProvider provider) 
          throws IOException, JsonProcessingException
      {
        jgen.writeStartObject();
        jgen.writeFieldName("bytes");
        jgen.writeStartArray();
        for (byte b : value.bytes)
          jgen.writeNumber(b);
        jgen.writeEndArray();
        jgen.writeEndObject();
      }
    }
    
    class ByteArrayAsIntegersSerializer extends JsonSerializer<byte[]>
    {
      @Override
      public void serialize(byte[] bytes, JsonGenerator jgen, SerializerProvider provider) 
          throws IOException, JsonProcessingException
      {
        jgen.writeStartArray();
        for (byte b : bytes)
          jgen.writeNumber(b);
        jgen.writeEndArray();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a multiplayer pacman game in Java for a university assignment
I have a generic class Proxy<T> , and I want to write another generic
i have to write an high efficiency sock reverse proxy in C/C++, so i
How can I determine if I have write permission on a remote machine in
I have to write an applet that brings up a password dialog. The problem
I have to write something in vbscript that need to use a unique set.
I have to write a component that re-creates SQL Server tables (structure and data)
I have to write a reliable, totally-ordered multicast system from scratch in Python. I
I have to write a program that read from a file that contains the
My understanding is that you have to write unit tests that isolate functionality. So

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.