19

I'm trying to pass python tuple over java xmlrpc. Here is library what I'm using: XMLPRC Java Libray

I'm using odoo framework on server and api. I want to pass argument which will looks like:

[(4,7),(4,8)]

I'm able to pass following structure:

[[4,7],[4,8]]

which is clearly array inside array like:

new Object[]{new Object[]{4,7},new Object[]{4,8}}

The problem is there is no tuple in java. What I absorb is how to transform this structure:

This [4,8] to This(4,8)

It is some kind of serialization issue what don't know how to resolve it and pass expected python structure.

Ashish Sahu
  • 1,538
  • 17
  • 22
  • 1
    Are you getting an error while trying to make the xmlrpc call ? Also, check the data types you can use on your library's documentation. – George Daramouskas Feb 08 '17 at 09:12
  • are you looking for a new class to define `(a, b)`, just like `http://stackoverflow.com/questions/10234487/storing-number-pairs-in-java?noredirect=1&lq=1` ? – Gang Feb 12 '17 at 18:21

5 Answers5

1

Is there a problem with [[4,7],[4,8]] ? Most python operations don't differ tuples from actual lists. And in Odoo even less. I think that this is the proper way to send a list of tuples through languages that does not implement tuples. Tuple is not a key, value thing. You can have (a, b, c) which is a tuple. That is somewhat similar to [a, b, c]. You can iterate on both. You can get their value through indexes (if both were stored in a element variable, getting a from it would be element[0] for them both).

So if you have a problem, I don't think it's about tuples and you did not answer the comment asking if there is an error on the XMLRPC call. My guess is there is no error. And if there is an error, I'm sure it's not about tuples.

Majikat
  • 722
  • 4
  • 13
0

A simple idea is to send it as string. Just like this in java:

String a="[[4,7],[4,8]]";

In python, you can simply use the eval() method to get it as array of arrays. If you want it as array of tuples, use:

String a="[(4,7),(4,8)]";

Just use the python syntax as string. In python, you can use:

my_list=eval(a)
print my_list[0]

It will give:

(4,7)

as output for the last example.

Mohammed Shareef C
  • 3,829
  • 25
  • 35
0

XML-RPC is limited. So, there is only one type for both list and tuple. If you look at docs for odoo you will see that both tuples and lists in Python examples transforms into Arrays.asList in Java. So, if you get some errors there is good probability that something else is wrong

mshutov
  • 792
  • 1
  • 5
  • 14
0

Did you try using the Apache commons Pair class? Docs.

Just did a quick test and this looks like what you want.

    System.out.println(new ImmutablePair<>(1,3).toString());
    (1,3)

The default serializer should output the Pair [] in the [(1,2),...] format you expect.

Michael Hibay
  • 522
  • 3
  • 11
0

After searching long time, I got solution. So I decided to answer it clearly. My answer is most likely to odoo side. So far I didn't find way to serialized that structure. But the odo frame accepted tuple in following manner:

[ [ 4, [7,8] ]

or

Arrays.asList(Arrays.asList(4, Arrays.asList(7,8)));

this is equivalent to:

[(4,3),(4,7)]

Hoping this will help someone.

Ashish Sahu
  • 1,538
  • 17
  • 22