// Path: xmlrpc/src/main/java/nl/nl2312/xmlrpc/types/Member.java
// @Root
// public final class Member {
// 
//     public static final String CODE = "member";
//     public static final String NAME = "name";
// 
//     @Element(name = NAME)
//     public String name;
// 
//     @Element(name = Value.CODE)
//     @Convert(ValueConverter.class)
//     public Value value;
// 
//     public void write(OutputNode node) throws Exception {
//         OutputNode member = node.getChild(CODE);
//         OutputNode nameNode = member.getChild(Member.NAME);
//         nameNode.setValue(name);
//         OutputNode valueNode = member.getChild(Value.CODE);
//         value.write(valueNode);
//     }
// 
//     public static Member create(String name, Value from) {
//         Member param = new Member();
//         param.name = name;
//         param.value = from;
//         return param;
//     }
// 
// }
// 
// Path: xmlrpc/src/main/java/nl/nl2312/xmlrpc/types/StructValue.java
// @Root(name = CODE)
// public final class StructValue implements Value {
// 
//     public static final String CODE = "struct";
// 
//     public StructValue(List<Member> members) {
//         this.members = members;
//     }
// 
//     @ElementList(inline = true)
//     public List<Member> members;
// 
//     @Override
//     public List<Member> value() {
//         return members;
//     }
// 
//     @Override
//     public void write(OutputNode node) throws Exception {
//         OutputNode struct = node.getChild(CODE);
//         for (Member member : members) {
//             member.write(struct);
//         }
//     }
// 
//     @Override
//     public Object asObject(DeserializationContext context, Class<?> type, Class<?> param) throws
//             IllegalAccessException, InstantiationException {
// 
//         if (context.hasStructDeserializer(type)) {
//             // Deserialize using custom deserializer
//             return context.structDeserializer(type).deserialize(new StructMembers(context, members));
//         }
// 
//         if (Map.class.isAssignableFrom(type)) {
//             Map t = new HashMap();
//             for (Member member : members) {
//                 t.put(member.name, member.value.asObject(context, param, null));
//             }
//             return t;
//         }
// 
//         // Deserialize using member to field mapping
//         Object t = type.newInstance();
//         for (Field field : type.getDeclaredFields()) {
//             Member fieldMember = findMember(field);
//             if (fieldMember != null && !Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field
//                     .getModifiers()) && !Modifier.isTransient(field.getModifiers())) {
//                 Class<?> targetFieldParam = null;
//                 if (field.getGenericType() instanceof ParameterizedType) {
//                     targetFieldParam = (Class<?>) ((ParameterizedType) field.getGenericType())
//                             .getActualTypeArguments()[0];
//                 }
//                 field.set(t, fieldMember.value.asObject(context, field.getType(), targetFieldParam));
//             }
//         }
//         return t;
//     }
// 
//     private Member findMember(Field field) {
//         for (Member member : members) {
//             MemberName memberName = field.getAnnotation(MemberName.class);
//             if (memberName != null && memberName.value().equals(member.name)) {
//                 return member;
//             } else if (memberName == null && field.getName().equals(member.name)) {
//                 return member;
//             }
//         }
//         return null;
//     }
// 
// }


import nl.nl2312.xmlrpc.types.Member;
import nl.nl2312.xmlrpc.types.StructValue;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
package nl.nl2312.xmlrpc;



@Root(name = "methodCall")
final class MethodCall {

    @Element
    String methodName;

    @ElementList
    List<Param> params;

    public static MethodCall create(String method, Object param) {
        MethodCall methodCall = new MethodCall();
        methodCall.methodName = method;

        if (param.getClass() == byte[].class) {
            methodCall.params = Collections.singletonList(Param.from(param));
        } else if (param.getClass().isArray()) {
            // Treat param as array of individual parameters
            int length = Array.getLength(param);
            methodCall.params = new ArrayList<>(length);
            for (int i = 0; i < length; i++) {
                methodCall.params.add(Param.from(Array.get(param, i)));
            }
        } else if (param instanceof Iterable) {
            // Treat param as collection of individual parameters
            Iterator iter = ((Iterable) param).iterator();
            methodCall.params = new ArrayList<>();
            while (iter.hasNext()) {
                methodCall.params.add(Param.from(iter.next()));
            }
        } else if (param instanceof Map) {
            // Treat param as struct with map entries as members
// Path: xmlrpc/src/main/java/nl/nl2312/xmlrpc/types/Member.java
// @Root
// public final class Member {
// 
//     public static final String CODE = "member";
//     public static final String NAME = "name";
// 
//     @Element(name = NAME)
//     public String name;
// 
//     @Element(name = Value.CODE)
//     @Convert(ValueConverter.class)
//     public Value value;
// 
//     public void write(OutputNode node) throws Exception {
//         OutputNode member = node.getChild(CODE);
//         OutputNode nameNode = member.getChild(Member.NAME);
//         nameNode.setValue(name);
//         OutputNode valueNode = member.getChild(Value.CODE);
//         value.write(valueNode);
//     }
// 
//     public static Member create(String name, Value from) {
//         Member param = new Member();
//         param.name = name;
//         param.value = from;
//         return param;
//     }
// 
// }
// 
// Path: xmlrpc/src/main/java/nl/nl2312/xmlrpc/types/StructValue.java
// @Root(name = CODE)
// public final class StructValue implements Value {
// 
//     public static final String CODE = "struct";
// 
//     public StructValue(List<Member> members) {
//         this.members = members;
//     }
// 
//     @ElementList(inline = true)
//     public List<Member> members;
// 
//     @Override
//     public List<Member> value() {
//         return members;
//     }
// 
//     @Override
//     public void write(OutputNode node) throws Exception {
//         OutputNode struct = node.getChild(CODE);
//         for (Member member : members) {
//             member.write(struct);
//         }
//     }
// 
//     @Override
//     public Object asObject(DeserializationContext context, Class<?> type, Class<?> param) throws
//             IllegalAccessException, InstantiationException {
// 
//         if (context.hasStructDeserializer(type)) {
//             // Deserialize using custom deserializer
//             return context.structDeserializer(type).deserialize(new StructMembers(context, members));
//         }
// 
//         if (Map.class.isAssignableFrom(type)) {
//             Map t = new HashMap();
//             for (Member member : members) {
//                 t.put(member.name, member.value.asObject(context, param, null));
//             }
//             return t;
//         }
// 
//         // Deserialize using member to field mapping
//         Object t = type.newInstance();
//         for (Field field : type.getDeclaredFields()) {
//             Member fieldMember = findMember(field);
//             if (fieldMember != null && !Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field
//                     .getModifiers()) && !Modifier.isTransient(field.getModifiers())) {
//                 Class<?> targetFieldParam = null;
//                 if (field.getGenericType() instanceof ParameterizedType) {
//                     targetFieldParam = (Class<?>) ((ParameterizedType) field.getGenericType())
//                             .getActualTypeArguments()[0];
//                 }
//                 field.set(t, fieldMember.value.asObject(context, field.getType(), targetFieldParam));
//             }
//         }
//         return t;
//     }
// 
//     private Member findMember(Field field) {
//         for (Member member : members) {
//             MemberName memberName = field.getAnnotation(MemberName.class);
//             if (memberName != null && memberName.value().equals(member.name)) {
//                 return member;
//             } else if (memberName == null && field.getName().equals(member.name)) {
//                 return member;
//             }
//         }
//         return null;
//     }
// 
// }


// Path: xmlrpc/src/main/java/nl/nl2312/xmlrpc/MethodCall.java
import nl.nl2312.xmlrpc.types.Member;
import nl.nl2312.xmlrpc.types.StructValue;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;

package nl.nl2312.xmlrpc;



@Root(name = "methodCall")
final class MethodCall {

    @Element
    String methodName;

    @ElementList
    List<Param> params;

    public static MethodCall create(String method, Object param) {
        MethodCall methodCall = new MethodCall();
        methodCall.methodName = method;

        if (param.getClass() == byte[].class) {
            methodCall.params = Collections.singletonList(Param.from(param));
        } else if (param.getClass().isArray()) {
            // Treat param as array of individual parameters
            int length = Array.getLength(param);
            methodCall.params = new ArrayList<>(length);
            for (int i = 0; i < length; i++) {
                methodCall.params.add(Param.from(Array.get(param, i)));
            }
        } else if (param instanceof Iterable) {
            // Treat param as collection of individual parameters
            Iterator iter = ((Iterable) param).iterator();
            methodCall.params = new ArrayList<>();
            while (iter.hasNext()) {
                methodCall.params.add(Param.from(iter.next()));
            }
        } else if (param instanceof Map) {
            // Treat param as struct with map entries as members
            ArrayList<Member> members = new ArrayList<>();