Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-4379

InjectionUtils failes to convert path-value to class annotated with XmlJavaTypeAdapter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.4, 2.6.1
    • Fix Version/s: 2.4.9, 2.5.5, 2.6.2, 2.7
    • Component/s: JAX-RS
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      package no.nrk.panorama.serum;
      
      import static org.fest.assertions.Assertions.assertThat;
      
      import java.lang.annotation.Annotation;
      
      import javax.xml.bind.annotation.adapters.XmlAdapter;
      import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
      
      import org.apache.cxf.jaxrs.model.ParameterType;
      import org.apache.cxf.jaxrs.utils.InjectionUtils;
      import org.apache.cxf.message.MessageImpl;
      import org.junit.Test;
      
      public class CXFInjectionUtilsJUnitTest {
      
      	public static class Adapter extends XmlAdapter<String, Id> {
      
      		@Override
      		public String marshal(final Id id) throws Exception {
      			return id.getId();
      		}
      
      		@Override
      		public Id unmarshal(final String idStr) throws Exception {
      			Id id = new DelegatingId();
      			id.setId(idStr);
      			return id;
      		}
      	}
      
      	@XmlJavaTypeAdapter(Adapter.class)
      	public interface Id {
      		public String getId();
      
      		public void setId(String id);
      	}
      
      	public static class DelegatingId implements Id {
      
      		private String id;
      
      		public String getId() {
      			return this.id;
      		}
      
      		public void setId(String id) {
      			this.id = id;
      		}
      
      	}
      
      	@Test
      	public void handleParameter_givenValidInput_shouldReturnIdWithCorrectValue() throws Exception {
      		// Arrange
      		String value = "1.1";
      
      		// Act
      		Object id = InjectionUtils.handleParameter(value, true, Id.class, new Annotation[] {}, ParameterType.PATH,
      		      new MessageImpl());
      
      		// Assert
      		assertThat(id).isInstanceOf(Id.class);
      		assertThat(((Id)id).getId()).isEqualTo(value);
      	}
      
      }
      
      

        Attachments

          Activity

            People

            • Assignee:
              sergey_beryozkin Sergey Beryozkin
              Reporter:
              erling Erling Holmqvist
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: