How to optimize JAXB deserialization of list of objects? - jaxb

I want to deserialize RSS channel and I have the following class:
#XmlAccessorType(XmlAccessType.NONE)
data class Channel(
#field:XmlElement
val item: List<Item>
)
I would like to stop deserializing this class after one element will appear in the item list since that list contains hundreds of items and I need only the first one.
Is there any annotation that I can put on item so JAXB will know that I need only one element?

Related

How can I map a single Row in Cassandra's Java Object-mapping API

I have a single com.datastax.driver.core.Row. I have a mapper class for this specific type of rows. How can I map the Row to my mapper class?
I need com.datastax.driver.mapping.Result.map(Row), however that function is private and non-static. Is there any other way?
I suggest creating a JIRA ticket to ask them to make the method public. Otherwise you can use Achilles, it offers exactly this mapping feature on a single Row:
https://github.com/doanduyhai/Achilles/wiki/Manager-API#other-methods
public ENTITY mapFromRow(Row row): map a given instance of com.datastax.driver.core.Row to an instance of ENTITY

Field not allowing loupe. gvnix 2.0.0.M1

We have two child classes: Child1,Child2 that inherits from the same a class ParentClass, and only the class ParentClass.
We have a class A that contains a field parentList of type set field. This parentList is a list of ParentClass instances Ids
private Set parentList = new HashSet();
What we really want to achieve, is to select multiple values from either Child1 and Child2, and assign them to the parentList set field in class A, using Loupe.
When we try to execute the loupe command over the parentList field of class A, we get the following error:
Field 'parentList' could not implement Loupe Field.
What are the restrictions on the fields to use Loupe?
Is what we want to achieve, possible?
This UI component is designed to handle relations between JPA Entities of type many-to-one in the many side of relation (field must be annotated with #ManyToOne).
Currently gvNIX doesn't include any component which handle #*ToMany relations the way you required. The most similar is the use of master-detail datatables (see web mvc datatables details add command). An example of this could be: master Vets and details Visits (selecting a Vet related Visits will be shown in details list).
The component you need can be done but you must create it by hand.
Good luck!

How to use Automapper to map multiple DataTables to an object

I've used Automapper before to map DataTable objects to a DTO object like this:
AutoMapper.CreateMap<IDataReader, MyDTO>();
Now I've run into a case where I have three DataTable objects that map to one DTO object. I can't use the simple case above because I have three sources with the same type.
Is there a way to specify some additional information, like the table name, to determine the correct mapping?

Binding a dictionary containing a list in MVC4

I am having trouble posting a form that contains a Dictionary that contains an int as a key and a list of objects as a value.
Originally this was just a List of Objects and that worked fine and the type was:
List<MyObject> Fields
the working markup was
Fields_{0}__Property1
where {0} is the index of the object. To get it to post back the List of Objects I rendered the object with hidden fields like this:
#Html.HiddenFor(m => m.Property1, new { Name = string.Format("Fields[{0}].Property1", Model.Index), #id = string.Format("Fields_{0}__Property1", Model.Index) })
This worked well. Now however, we have a dictionary instead of a list and the list is inside the dictionary.
Now the type is:
Dictionary<int, List<MyObject>>.
I tested the format expected when we render the dictionary using Html.HiddenFor and so I've added hidden fields with the required format which now is:
#Html.HiddenFor(m => m.Property1, new { Name = string.Format("Fields[{0}][{1}].Property1", Model.Index, Model.Position), #id = string.Format("Fields_{0}__{1}__Property1", Model.Index, Model.Position) })
now the field id is
Fields_{0}__{1}__Property1
where {0} is the key of the dictionary and {1} is the index of the object in the list.
However on postback I now get
[InvalidCastException: Specified cast is not valid.]
System.Web.Mvc.CollectionHelpers.ReplaceDictionaryImpl(IDictionary`2 dictionary, IEnumerable`1 newContents) +131
I am guessing MVC is smart enough to render the fields of this complex object on the view but not smart enough to collect them back into the viewmodel when we post back.
I found this other guy who had a similar problem here and he solved it by not using a dictionary but instead creating a complex object. I'm wondering, however, if there's a quicker way that won't require me to rewrite the entire system.
Any ideas?
Update
I solved it by taking the source code of DefaultModelBinder and adjusting it.
I found the source here. I didn't create my own Binder because I want all the advanced functionality and validation rules to apply to all other elements.
Once I got the DefaultModelBinder compiling and working I found the part where the dictionary was failing to cast the complex items and wrote a custom Dictionary update method that solved the problem
You can always create a custom Model Binder to bind objects from request values exactly as you want. Simply create a class that implements the System.Web.Mvc.IModelBinder interface and implement the BindModel() method.

Finding JAXB generated class for root element

I am new to using JAXB. I need to generate an xml file from its schema, where the schema and element values are input from the user.
My problem is, if I don't know the name of the elements beforehand, how can I use the JAXB generated classes? Is there a generic function, like getRoot() or getChildren() which I can use to traverse through the classes?

Resources