I use JAXB for mapping XML configuration to Java object. This configuration could be edited from UI, that's why in order to transfer it to UI and vice versa. I definitely need to unmarshall json into Java object. Hence it's required to have setter method for List.
How to generate setter method for List property for POJO class using JAXB?
For security reasons setter are not generated for List objects.
/**
* Gets the value of the dateIntervals property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the dateIntervals property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getDateIntervals().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {#link DateInterval }
*
*
*/
For that you need create variable of List.The setter getter methods for this List variable are as below.
package foo.bar.me.too;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name="VisitorDataList")
public class visitordatalist {
List<visitordata> vstd;
#XmlElement(name="VisitorData")
public List<visitordata> getVstd() {
return vstd;
}
public void setVstd(List<visitordata> vstd) {
this.vstd = vstd;
}
}
Related
I have a list of List<ManagedInstance>
I'm looking for this equivalant in java-8 - how to find an external ip of a ManagedInstance ?
I saw in the java-doc, but found no "external IP" property.
#SuppressWarnings("javadoc")
public final class ManagedInstance extends /**
* [Output only] The unique identifier for this resource. This field is empty when instance does
* not exist.
* The value may be {#code null}.
*/
#com.google.api.client.util.Key #com.google.api.client.json.JsonString
private java.math.BigInteger id;
/**
* [Output Only] The URL of the instance. The URL can exist even if the instance has not yet been
* created.
* The value may be {#code null}.
*/
#com.google.api.client.util.Key
private java.lang.String instance;
/**
* [Output Only] The status of the instance. This field is empty when the instance does not exist.
* The value may be {#code null}.
*/
#com.google.api.client.util.Key
private java.lang.String instanceStatus;
...
I have an enum codes in JAVA. I convert all JAVA code to DELPHI.
I almost done, but i stucked in here. I have no idea, how to convert enum to Delphi.
I am wondering, this code can be convert to Delphi ?
/**
* Enum describing the databin class ID's. Methods exist for getting the
* KakaduClassID and the StandardClassID. I have also included the string
* representations of the databins as defined for cache model updates.
*
*
*/
public enum JPIPDatabinClass {
/** Precinct data bin class. */
PRECINCT_DATABIN(KakaduConstants.KDU_PRECINCT_DATABIN, JPIPConstants.PRECINCT_DATA_BIN_CLASS, "P"),
/** Tile Header data bin class. */
TILE_HEADER_DATABIN(KakaduConstants.KDU_TILE_HEADER_DATABIN, JPIPConstants.TILE_HEADER_DATA_BIN_CLASS, "H"),
/** Tile data bin class. */
TILE_DATABIN(KakaduConstants.KDU_TILE_DATABIN, JPIPConstants.TILE_DATA_BIN_CLASS, "T"),
/** Main Header data bin class. */
MAIN_HEADER_DATABIN(KakaduConstants.KDU_MAIN_HEADER_DATABIN, JPIPConstants.MAIN_HEADER_DATA_BIN_CLASS, "Hm"),
/** Meta data bin class. */
META_DATABIN(KakaduConstants.KDU_META_DATABIN, JPIPConstants.META_DATA_BIN_CLASS, "M");
/** The classID as an integer as per the Kakadu library. */
private int kakaduClassID;
/** The classID as an integer as per the JPEG2000 Part-9 standard. */
private int standardClassID;
/**
* The classID as a string as per the JPEG2000 Part-9 standard. Used for
* cache model updates.
*/
private String jpipString;
/**
* Constructor.
*
* #param _kakaduClassID
* #param _standardClassID
* #param _jpipString
*/
JPIPDatabinClass(int _kakaduClassID, int _standardClassID, String _jpipString) {
kakaduClassID = _kakaduClassID;
standardClassID = _standardClassID;
jpipString = _jpipString;
}
/** Returns the classID as an integer as per the Kakadu library. */
public int getKakaduClassID() {
return kakaduClassID;
}
/** Returns the classID as an integer as per the JPEG2000 Part-9 standard. */
public int getStandardClassID() {
return standardClassID;
}
/**
* Returns the classID as a string as per the JPEG2000 Part-9 standard. Used
* for cache model updates.
*/
public String getJpipString() {
return jpipString;
}
};
This Enum can easily be translated to a plain old Delphi class which has a three-argument constructur like the Java Enum, and three read-only public properties.
JPIPDatabinClass = class(TObject)
private
...
public
constructor Create(AKakaduClassID: Integer; AStandardClassID: Integer; AJPIP: string);
property KakaduClassID: Integer; read FKakaduClassID;
property StandardClassID: Integer; read FStandardClassID;
property JPIP: string; read FJPIP;
end;
and 'singleton style' instances:
function PRECINCT_DATABIN: JPIPDatabinClass;
function TILE_HEADER_DATABIN: JPIPDatabinClass;
...
implementation
var
FPRECINCT_DATABIN: JPIPDatabinClass;
FTILE_HEADER_DATABIN: JPIPDatabinClass;
...
FPRECINCT_DATABIN := JPIPDatabinClass.Create( ... );
FTILE_HEADER_DATABIN := JPIPDatabinClass.Create( ... );
...
function PRECINCT_DATABIN: JPIPDatabinClass;
begin
Result := FPRECINCT_DATABIN;
end;
function TILE_HEADER_DATABIN: JPIPDatabinClass;
begin
Result := FTILE_HEADER_DATABIN;
end;
...
Note: the disadvantage of this approach is that does not create real Delphi enum types, it only emulates the Java enum type as immutable Delphi objects.
As topic states, I want to remove non-objects from List of objects.
I have a web service (xml file with some data) and generated classes from XSD file. Among generated XSD classes there is a class ASMENYS and it has method getContent(). This method returns a list of generated.ASMUO objects.
Now the problem is, that this method for some reason returns empty lines (spaces?) among objects. I need to iterate through asmenysList, and because of empty spaces I'm forced to use if() which deprecates my code performance...Any ideas? Why are those empty spaces generated? Or maybe some ideas how to better filter them without iteration if possible?
//m here is generated.ASMENYS object,.: generated.ASMENYS#10636b0
List<Object> asmenysList = ((ASMENYS) m).getContent();
System.out.println(asmenysList);
[
, generated.ASMUO#1799640,
, generated.ASMUO#b107fd,
, generated.ASMUO#10636b0,
...
, generated.ASMUO#1df00a0,
]
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"content"
})
#XmlRootElement(name = "ASMENYS")
public class ASMENYS {
#XmlElementRef(name = "ASMUO", type = ASMUO.class, required = false)
#XmlMixed
protected List<Object> content;
/**
* Gets the value of the content property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the content property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getContent().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {#link ASMUO }
* {#link String }
*
*
*/
public List<Object> getContent() {
if (content == null) {
content = new ArrayList<Object>();
}
return this.content;
}
}
EDIT
/**
* Gets the value of the asmId property.
*
*/
public int getAsmId() {
return asmId;
}
List<Object> asmenysList = ((ASMENYS) m).getContent();
for(Object asm : asmenysList){
//trying to cast empty asmenysList element, gives me an error.
//that's why I'm forced to use if() as I said before.
if(asm.getClass().getName() == "generated.ASMUO"){
int asm_id = ((ASMUO) asm).getAsmId();
}
}
By definition a List<Object> only holds Object(s). If there are primitive types in there, they must be autoboxed. If it's an array, that is an Object. The only empty spaces I see are from the toString() method of List.
Edit
based on your edit,
if(asm.getClass().getName() == "generated.ASMUO"){
Is not how you test String equality,
if(asm.getClass().getName().equals("generated.ASMUO")) {
I'm working with Mybatis 3.2.6 and implementing a custom resulthandler. I've done this before using a simple datatype parameter and have had no problems. This time around I need to pass in several arguments... The signature I'm using is
session.select(statement, parameter, handler);
For parameter I've created a simple POJO to easily send in what I need. It is as follows:
public class DifferenceParam {
private int current;
private int compare;
private String table;
private String comparator;
/**
* Constructor excluding comparator. Will default a value of
* "code" to compare content on, e.g., <br/>
* {#code select * from a minus select * from b where a.code = b.code } <br/>
* #param table
* #param current
* #param compare
*/
public DifferenceParam(String table, int current, int compare) {
this(table, "code", current, compare);
}
/**
* Constructor providing a specific column to compare on, e.g. <br/>
* {#code select * from a minus select * from b where a.[comparator] = b.[comparator] } <br/>
* #param table
* #param comparator
* #param current
* #param compare
*/
public DifferenceParam(String table, String comparator, int current, int compare) {
this.table = table;
this.comparator = comparator;
this.current = current;
this.compare = compare;
}
/** Appropriate setters and getters to follow **/
}
The handler implementation is irrelevant at the moment, because I get an exception well in advance... The query I'm executing is:
<select id="getCodeSetModifications" parameterType="DifferenceParam" resultType="Code">
select *
from
(
select * from ${param.table} where revision_seq = #{param.current}
minus
select * from ${param.table} where revision_seq = #{param.compare}
) a, ${param.table} b
where a.${param.comparator} = b.${param.comparator}
and b.revision_seq = #{param.compare}
</select>
Here is the interface as well
public List<Code> getCodeSetModifications(#Param("param") DifferenceParam param);
The problem I'm having is that execution via a mapper e.g.,
session.getMapper(DifferenceParam.class);
works just fine, but when I invoke through a select on the session I get the following exception.
Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.mmm.his.cer.cerval.uidifference.map.param.DifferenceParam'
Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.mmm.his.cer.cerval.uidifference.map.param.DifferenceParam'
I've debugged as far as I can go into Mybatis, but am having no luck.
Thanks in advance...
When you use session.getMapper(DifferenceParam.class);, mybatis looks for #Param annotation and uses it's value in query.
When you invoke session.select(statement, parameter, handler);, such mapping doesn't occur.
Try to add public DifferenceParam getParam() { return this; } to DifferenceParam to workaround this.
when the MyBatis query only have one param. Don't need #{param.} reference.
because it default use the only param.
so when u use ${param.table}, it actually using #{DifferenceParam.param.table}.
because it think the ${param.} inside of the #{DifferenceParam.}
I have build an application for dynamic compile java source code and fetch the compiled class information and stored to object.
The application required source directory and full qualify class name (ex. MOCG.entity.Person) for adding file to the application.
I use the Janino compiler in this application. I used to implement by javax.tools.ToolProvider compiler but I dont know how to compile multiple file, and it cannot automatically compile related class.
For now my code work just fine but when I try to compile an interface class or abstract class it always return error :
Caused by: org.codehaus.commons.compiler.CompileException: File /Users/chillyprig/IdeaProjects/Mockito/src/lab05/p1/dao/CourseDAO.java, Line 22, Column 9: Identifier expected in member declaration
at org.codehaus.janino.Parser.throwCompileException(Parser.java:2593)
at org.codehaus.janino.Parser.parseInterfaceBody(Parser.java:613)
at org.codehaus.janino.Parser.parseInterfaceDeclarationRest(Parser.java:518)
at org.codehaus.janino.Parser.parsePackageMemberTypeDeclaration(Parser.java:186)
at org.codehaus.janino.Parser.parseCompilationUnit(Parser.java:74)
at org.codehaus.janino.JavaSourceIClassLoader.findIClass(JavaSourceIClassLoader.java:150)
... 46 more
This is an input file :
/**
* Created with IntelliJ IDEA.
* User: Dto
* Date: 12/2/12
* Time: 8:26 AM
* To change this template use File | Settings | File Templates.
*/
package lab05.p1.dao;
import java.util.List;
import java.util.Set;
/**
* This is the example of the DAO interface, you have to implement the implementation class to complete the DAO classes
* #author dto
*/
public interface CourseDAO {
/**
* Get all the courses
* #return all courses stored in the persistence
*/
List<Course> getCourses();
/**
* Get all students which enroll to the courses
* #return all students in the persistence
*/
Set<Student> getStudents();
/**
* Get the course by query the name provided
* #param name the name of the course which the user wants
* #return the course which contains the same name
* null if the course with specific name is not existed
*/
Course getCourseByName(String name);
/**
* Get the Student by id
* #param id the id of the student which we want to find
* #return the student object with the specific id
* The empty student object if the student with the specific id is not exist
*/
Student getStudentById(String id);
}
This is my snipped code for compilation :
private Class compile() throws ClassNotFoundException, SourceDirectoryNotfoundException {
ClassLoader classLoader = null;
try{
classLoader = new JavaSourceClassLoader(
Thread.currentThread().getContextClassLoader(),
new File[] {new File(sourceDir)},
(String) null
);
} catch (NullPointerException e){
throw new SourceDirectoryNotfoundException();
}
Class<?> c = classLoader.loadClass(fullname);
return c;
}
Every suggestion is very appreciate. Any code example would be nice.
Janino is a Java 1.4 compatible compiler -- i.e., it can't handle generics, which were introduced in Java 5. Line 22 is the line that begins List<Course> -- a use of generics, which this compiler can't handle.