@Override
  public String nameForSerialization(final BeanPropertyDefinition beanProperty) {

    SerializationConfig serializationConfig = objectMapper.getSerializationConfig();

    Optional<PropertyNamingStrategy> namingStrategy =
        Optional.fromNullable(serializationConfig.getPropertyNamingStrategy());
    String newName =
        namingStrategy
            .transform(overTheWireName(beanProperty, serializationConfig))
            .or(beanProperty.getName());

    LOG.debug("Name '{}' renamed to '{}'", beanProperty.getName(), newName);

    return newName;
  }
 private void findId() {
   if (idMethod == null && idProperty == null) {
     SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
     JavaType javaType = serializationConfig.constructType(entityClass);
     BeanDescription beanDescription = serializationConfig.introspect(javaType);
     List<BeanPropertyDefinition> properties = beanDescription.findProperties();
     for (BeanPropertyDefinition property : properties) {
       /* Constructor parameters don't work because they give us no value accessor
       if ( property.hasConstructorParameter() ) {
           AnnotatedParameter parameter = property.getConstructorParameter();
           if ( parameter.getAnnotation(Id.class) != null ) {
               idPropertyName = property.getName();
           }
       }
       */
       if (property.hasField()) {
         Field field = property.getField().getAnnotated();
         if (field.getAnnotation(Id.class) != null) {
           idPropertyName = property.getName();
           idProperty = field;
           break;
         }
       }
       if (property.hasGetter()) {
         Method getter = property.getGetter().getAnnotated();
         if (getter.getAnnotation(Id.class) != null) {
           idPropertyName = property.getName();
           idMethod = getter;
           break;
         }
         if (property.hasSetter()) {
           Method setter = property.getSetter().getAnnotated();
           if (setter.getAnnotation(Id.class) != null) {
             idPropertyName = property.getName();
             idMethod = getter;
             break;
           }
         }
       }
       // setter only doesn't work because it gives us no value accessor
     }
   }
   // Jackson's introspect approach should find it, but our old approach below
   // gives some helpful errors
   if (idMethod == null && idProperty == null) {
     for (Method method : entityClass.getDeclaredMethods()) {
       if (method.isAnnotationPresent(Id.class)) {
         Class<?>[] parameters = method.getParameterTypes();
         if (!Modifier.isPublic(method.getModifiers())) {
           throw new IllegalStateException(
               "Your method, "
                   + method.getName()
                   + ", annotated with com.marklogic.client.pojo.annotation.Id "
                   + " must be public");
         }
         if (parameters == null || parameters.length == 0) {
           Matcher matcher = getterPattern.matcher(method.getName());
           if (matcher.matches()) {
             idPropertyName = matcher.group(2).toLowerCase() + matcher.group(3);
             idMethod = method;
             break;
           } else {
             throw new IllegalStateException(
                 "Your no-args method, "
                     + method.getName()
                     + ", annotated with com.marklogic.client.pojo.annotation.Id "
                     + " must be a proper getter method and begin with \"get\" or \"is\"");
           }
         } else {
           Matcher getterMatcher = getterPattern.matcher(method.getName());
           if (getterMatcher.matches()) {
             throw new IllegalStateException(
                 "Your getter method, "
                     + method.getName()
                     + ", annotated with com.marklogic.client.pojo.annotation.Id "
                     + " must not require any arguments");
           } else if (method.getName().startsWith("set")) {
             throw new MarkLogicInternalException(
                 "Your setter method, "
                     + method.getName()
                     + ", annotated with com.marklogic.client.pojo.annotation.Id "
                     + "was not found by Jackson for some reason.  Please report this to "
                     + "MarkLogic support.");
           } else {
             throw new IllegalStateException(
                 "Your setter method, "
                     + method.getName()
                     + ", annotated with com.marklogic.client.pojo.annotation.Id "
                     + " must be a proper setter method (beginning with \"set\")");
           }
         }
       }
     }
     if (idMethod == null) {
       for (Field field : entityClass.getDeclaredFields()) {
         if (field.isAnnotationPresent(Id.class)) {
           if (!Modifier.isPublic(field.getModifiers())) {
             throw new IllegalStateException(
                 "Your field, "
                     + field.getName()
                     + ", annotated with com.marklogic.client.pojo.annotation.Id "
                     + " must be public");
           }
           idProperty = field;
           break;
         }
       }
     }
   }
 }
示例#3
0
 private boolean isEnabled(JsonProvider provider, SerializationFeature feature) {
   ObjectMapper mapper = provider.locateMapper(Object.class, MediaType.APPLICATION_JSON_TYPE);
   SerializationConfig sConfig = mapper.getSerializationConfig();
   return sConfig.isEnabled(feature);
 }