public String defaultValue() { return core.defaultValue(); }
public static String findDefaultValue(Object jaxbObject, String fieldName) { Field declaredField = null; Class<?> clazz = jaxbObject.getClass(); while (true) { try { declaredField = clazz.getDeclaredField(fieldName); break; } catch (NoSuchFieldException nsfe) { clazz = clazz.getSuperclass(); if (clazz.equals(Object.class)) { break; } } } if (declaredField == null) { throw new IllegalArgumentException("No such field '" + fieldName + "' in JAXB class " + jaxbObject.getClass().getName()); } XmlElement annotation = declaredField.getAnnotation(XmlElement.class); return annotation != null ? annotation.defaultValue() : null; }
protected String resolveDefaultValue(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) { if (schema != null) { if (!schema.defaultValue().isEmpty()) { return schema.defaultValue(); } } if (a == null) { return null; } XmlElement elem = a.getAnnotation(XmlElement.class); if (elem == null) { if (annotations != null) { for (Annotation ann: annotations) { if (ann instanceof XmlElement) { elem = (XmlElement)ann; break; } } } } if (elem != null) { if (!elem.defaultValue().isEmpty() && !"\u0000".equals(elem.defaultValue())) { return elem.defaultValue(); } } return null; }
public String defaultValue() { return core.defaultValue(); }
if((!nav().isPrimitive(type) || isCollection()) && !item.required()) isRequired = false; types.add(createTypeRef(name, type, item.nillable(), getDefaultValue(item.defaultValue()) ));
public String defaultValue() { return core.defaultValue(); }
public String defaultValue() { return core.defaultValue(); }
/** * The default value, or null if none exists. * * @return The default value, or null if none exists. */ public String getDefaultValue() { String defaultValue = null; if ((xmlElement != null) && (!"\u0000".equals(xmlElement.defaultValue()))) { defaultValue = xmlElement.defaultValue(); } return defaultValue; }
/** * The default value, or null if none exists. * * @return The default value, or null if none exists. */ public String getDefaultValue() { String defaultValue = null; if ((xmlElement != null) && (!"\u0000".equals(xmlElement.defaultValue()))) { defaultValue = xmlElement.defaultValue(); } return defaultValue; }
/** * The default value, or null if none exists. * * @return The default value, or null if none exists. */ public String getDefaultValue() { String defaultValue = null; if ((xmlElement != null) && (!"\u0000".equals(xmlElement.defaultValue()))) { defaultValue = xmlElement.defaultValue(); } return defaultValue; }
/** * The default value, or null if none exists. * * @return The default value, or null if none exists. */ public String getDefaultValue() { String defaultValue = null; if ((xmlElement != null) && (!"\u0000".equals(xmlElement.defaultValue()))) { defaultValue = xmlElement.defaultValue(); } return defaultValue; }
if((!nav().isPrimitive(type) || isCollection()) && !item.required()) isRequired = false; types.add(createTypeRef(name, type, item.nillable(), getDefaultValue(item.defaultValue()) ));
private static void setDefault(Object o, String fieldName) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException { final Field field = o.getClass().getDeclaredField(fieldName); final Method getter = o.getClass().getDeclaredMethod("get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1)); final Method setter = o.getClass().getDeclaredMethod("set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1), getter.getReturnType()); final Object getResult = getter.invoke(o); setter.invoke(o, getResult == null ? field.getAnnotation(XmlElement.class).defaultValue() : (getResult instanceof String ? getResult.toString().trim() : getResult)); }
public class Test { public static void main(String[] args) throws NoSuchMethodException, SecurityException { Method method = Employee.class.getMethod("getName"); XmlElement anno =method.getAnnotation(javax.xml.bind.annotation.XmlElement.class); System.out.println(anno.name()); System.out.println(anno.defaultValue()); }
public static void setDefaultValues(Object o) throws Exception { if (o == null) return; for (Class<?> clazz = o.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) { for (final Field f : clazz.getDeclaredFields()) { final XmlElement xe = f.getAnnotation(XmlElement.class); if (xe != null && xe.defaultValue() != null) { final Class<?> t = f.getType(); if (t.isAssignableFrom(String.class)) { f.setAccessible(true); f.set(o, xe.defaultValue()); } else if (t.isAssignableFrom(Integer.class) || clazz.getSimpleName().equals("int")) { f.setAccessible(true); f.set(o, Integer.parseInt(xe.defaultValue())); } else if (t.isAssignableFrom(Long.class) || clazz.getSimpleName().equals("long")) { f.setAccessible(true); f.set(o, Long.parseLong(xe.defaultValue())); } // else { // TODO: add futher conversions // } } } } }
public static String findDefaultValue(Object jaxbObject, String fieldName) { Field declaredField = null; Class<?> clazz = jaxbObject.getClass(); while (true) { try { declaredField = clazz.getDeclaredField(fieldName); break; } catch (NoSuchFieldException nsfe) { clazz = clazz.getSuperclass(); if (clazz.equals(Object.class)) { break; } } } if (declaredField == null) { throw new IllegalArgumentException("No such field '" + fieldName + "' in JAXB class " + jaxbObject.getClass().getName()); } XmlElement annotation = declaredField.getAnnotation(XmlElement.class); return annotation != null ? annotation.defaultValue() : null; }
@Override public void beforeMarshal(Object source) { try { PropertyDescriptor[] descriptors = Introspector.getBeanInfo(source.getClass()).getPropertyDescriptors(); for(PropertyDescriptor descriptor:descriptors){ if(descriptor.getReadMethod() != null){ Object currentValue=descriptor.getReadMethod().invoke(source); XmlElement xmlElement = descriptor.getReadMethod().getAnnotation(XmlElement.class); String defaultValue=null; if(xmlElement != null){ defaultValue=xmlElement.defaultValue(); } if(currentValue != null && currentValue.toString().equals(defaultValue)){ if(descriptor.getWriteMethod() != null){ descriptor.getWriteMethod().invoke(source, new Object[]{null}); } } } } } catch (IntrospectionException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } catch (InvocationTargetException ex) { throw new RuntimeException(ex); } }
protected String resolveDefaultValue(Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema) { if (schema != null) { if (!schema.defaultValue().isEmpty()) { return schema.defaultValue(); } } if (a == null) { return null; } XmlElement elem = a.getAnnotation(XmlElement.class); if (elem == null) { if (annotations != null) { for (Annotation ann: annotations) { if (ann instanceof XmlElement) { elem = (XmlElement)ann; break; } } } } if (elem != null) { if (!elem.defaultValue().isEmpty() && !"\u0000".equals(elem.defaultValue())) { return elem.defaultValue(); } } return null; }
private static void setDefault(Configuration configuration) throws NoSuchFieldException { for (Source source : configuration.getSources()) { if (source.getConverter() == null) source.setConverter(Source.class.getField("converter").getAnnotation(XmlElement.class).defaultValue()); if (source.getSourceEncoding() == null) source.setSourceEncoding(Source.class.getField("sourceEncoding").getAnnotation(XmlElement.class).defaultValue()); if (source.getTargetDir() == null) source.setTargetDir(Source.class.getField("targetDir").getAnnotation(XmlElement.class).defaultValue()); if (source.getTargetEncoding() == null) source.setTargetEncoding(Source.class.getField("targetEncoding").getAnnotation(XmlElement.class).defaultValue()); if (source.getExcludes() == null) source.setExcludes(Source.class.getField("excludes").getAnnotation(XmlElement.class).defaultValue()); if (source.isOverwrite() == null) source.setOverwrite(Boolean.valueOf(Source.class.getField("overwrite").getAnnotation(XmlElement.class).defaultValue())); if (source.isDescribeByNative() == null) source.setDescribeByNative(Boolean.valueOf(Source.class.getField("describeByNative").getAnnotation(XmlElement.class).defaultValue())); if (source.isToMessageProperties() == null) source.setToMessageProperties(Boolean.valueOf(Source.class.getField("toMessageProperties").getAnnotation(XmlElement.class).defaultValue())); } }
av0.visit("required", el.required()); av0.visit("namespace", el.namespace()); av0.visit("defaultValue", el.defaultValue()); if (el.type() != XmlElement.DEFAULT.class) { av0.visit("type", el.type());