Index: rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/OrderException.java
===================================================================
--- rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/OrderException.java	(revision 0)
+++ rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/OrderException.java	(revision 1509251)
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessOrder;
+import javax.xml.bind.annotation.XmlAccessorOrder;
+
+@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL)
+public class OrderException extends Exception {
+    private static final long serialVersionUID = 1L;
+
+    private String info1;
+
+    private String info2;
+
+    private String aValue;
+
+    private int intVal;
+
+    private String detail;
+
+    public OrderException(String message) {
+        super(message);
+    }
+
+
+    public String getAValue() {
+        return aValue;
+    }
+
+    public void setAValue(String value) {
+        this.aValue = value;
+    }
+
+    public String getInfo1() {
+        return info1;
+    }
+
+    public void setInfo1(String info1) {
+        this.info1 = info1;
+    }
+
+    public String getInfo2() {
+        return info2;
+    }
+
+    public void setInfo2(String info2) {
+        this.info2 = info2;
+    }
+
+
+    public int getIntVal() {
+        return intVal;
+    }
+
+    public void setIntVal(int intVal) {
+        this.intVal = intVal;
+    }
+
+    public String getDetail() {
+        return detail;
+    }
+
+    public void setDetail(String detail) {
+        this.detail = detail;
+    }
+
+}

Property changes on: rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/OrderException.java
___________________________________________________________________
Added: svn:eol-style
   + native
Added: svn:keywords
   + Rev Date

Index: rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
===================================================================
--- rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java	(revision 1509137)
+++ rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java	(revision 1509251)
@@ -56,8 +56,13 @@
 import org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement;
 import org.apache.cxf.jaxb_misc.Base64WithDefaultValueType;
 import org.apache.cxf.jaxb_misc.ObjectFactory;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.staxutils.StaxStreamFilter;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.hello_world_soap_http.types.GreetMe;
 import org.apache.hello_world_soap_http.types.GreetMeResponse;
 import org.apache.hello_world_soap_http.types.StringStruct;
@@ -429,6 +434,47 @@
     }
 
     @Test
+    public void testMarshallExceptionWithOrder() throws Exception {
+        Document doc = DOMUtils.createDocument();
+        Element elNode = doc.createElementNS("http://cxf.apache.org",  "ExceptionRoot");
+        
+        OrderException exception = new OrderException("Mymessage");
+        exception.setAValue("avalue");
+        exception.setDetail("detail");
+        exception.setInfo1("info1");
+        exception.setInfo2("info2");
+        exception.setIntVal(10000);
+       
+        QName elName = new QName("http://cxf.apache.org", "OrderException");       
+        ServiceInfo serviceInfo = new ServiceInfo();
+        InterfaceInfo interfaceInfo = new InterfaceInfo(serviceInfo, null);
+        OperationInfo op = interfaceInfo.addOperation(new QName("http://cxf.apache.org", "operation"));     
+        MessageInfo message = new MessageInfo(op, null, null);
+        MessagePartInfo part = new MessagePartInfo(elName, message);
+        part.setElement(true);
+        part.setElementQName(elName);
+        part.setTypeClass(OrderException.class);
+            
+        //just need a simple generic context to handle the exceptions internal primitives
+        JAXBContext exceptionContext = JAXBContext.newInstance(new Class[] {
+            String.class,
+        });
+        JAXBEncoderDecoder.marshallException(exceptionContext.createMarshaller(), exception, part, elNode);
+        
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        StaxUtils.writeTo(elNode, bout);
+        int a = bout.toString().lastIndexOf("aValue");
+        int b = bout.toString().lastIndexOf("detail");
+        int c = bout.toString().lastIndexOf("info1");
+        int d = bout.toString().lastIndexOf("info2");
+        int e = bout.toString().lastIndexOf("intVal");
+        assertTrue(a < b);
+        assertTrue(b < c);
+        assertTrue(c < d);
+        assertTrue(d < e);
+    }
+    
+    @Test
     public void testMarshallWithoutQNameInfo() throws Exception {
         GreetMe obj = new GreetMe();
         obj.setRequestType("Hello");
Index: rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
===================================================================
--- rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java	(revision 1509137)
+++ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java	(revision 1509251)
@@ -26,6 +26,7 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
@@ -37,6 +38,8 @@
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.List;
@@ -49,7 +52,9 @@
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessOrder;
 import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorOrder;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
 import javax.xml.bind.attachment.AttachmentMarshaller;
@@ -357,9 +362,31 @@
             } else {
                 LOG.warning("Schema associated with " + namespace + " is null");
             }
+            List<Member> combinedMembers = new ArrayList<Member>();
+
+
             for (Field f : Utils.getFields(cls, accessType)) {
                 XmlAttribute at = f.getAnnotation(XmlAttribute.class);
                 if (at == null) {
+                    combinedMembers.add(f);
+                }
+            }
+            for (Method m : Utils.getGetters(cls, accessType)) {
+                combinedMembers.add(m);
+            }
+
+            XmlAccessorOrder xmlAccessorOrder = cls.getAnnotation(XmlAccessorOrder.class);
+            if (xmlAccessorOrder != null && xmlAccessorOrder.value().equals(XmlAccessOrder.ALPHABETICAL)) {
+                Collections.sort(combinedMembers, new Comparator<Member>() {
+                    public int compare(Member m1, Member m2) {
+                        return m1.getName().compareTo(m2.getName());
+                    }
+                });
+            }
+
+            for (Member member : combinedMembers) {
+                if (member instanceof Field) {
+                    Field f = (Field)member;
                     QName fname = new QName(namespace, f.getName());
                     ReflectionUtil.setAccessible(f);
                     if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
@@ -368,20 +395,20 @@
                         Object o = Utils.getFieldValue(f, elValue); 
                         writeObject(marshaller, writer, newJAXBElement(fname, String.class, o));
                     }
+                } else { // it's a Method
+                    Method m = (Method)member;
+                    int idx = m.getName().startsWith("get") ? 3 : 2;
+                    String name = m.getName().substring(idx);
+                    name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
+                    QName mname = new QName(namespace, name);
+                    if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
+                        writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
+                    } else {
+                        Object o = Utils.getMethodValue(m, elValue); 
+                        writeObject(marshaller, writer, new JAXBElement(mname, String.class, o));
+                    }
                 }
             }
-            for (Method m : Utils.getGetters(cls, accessType)) {
-                int idx = m.getName().startsWith("get") ? 3 : 2;
-                String name = m.getName().substring(idx);
-                name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
-                QName mname = new QName(namespace, name);
-                if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
-                    writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
-                } else {
-                    Object o = Utils.getMethodValue(m, elValue); 
-                    writeObject(marshaller, writer, newJAXBElement(mname, String.class, o));
-                }
-            }
 
             writer.writeEndElement();
             writer.flush();
