XStream ignoring first propery's alias - web-services

I've been struggling with an issue for more than 6 hours and searching for the issue on the web is not being much of help.
There's this class which I use to generate a XML (XStream from Thoughworks). It works fine everywhere within the application, except for one class. The ALIAS are annotated in the class and the very first property, no matter which it is, its ALIAS is ignored.
Here is the class:
#XStreamAlias("FNCGRAVAPREMATRICULATITULAR")
public class PreMatriculaTitular {
#XStreamAlias("NOME")
private String nome;
#XStreamAlias("NASCIMENTO")
private Date nascimento;
#XStreamAlias("SEXO")
private String sexo;
#XStreamAlias("CIV_CODIGO")
private Integer civCodigo;
.
.
.
But the XML generated is:
<FNCGRAVAPREMATRICULATITULAR>
<nome>QA click</nome>
<NASCIMENTO>17091989</NASCIMENTO>
<SEXO>M</SEXO>
<CIV_CODIGO>1</CIV_CODIGO>
.
.
.
Somehow XStream is ignoring the first field's ALIAS. I tried moving fields up and down and it always happens with the first property, no matter which it is.
The whole project is built using XStream and #XStreamAlias so I cannot change the way things are done. I must use XStream and annotation.
XStream version is 1.4.7, Java 1.6 with Spring and other gadgets.
Thank you for your time.

Related

Grails Domain Class String List

i try to make a String list in Grails.
My part therefore are:
class Name{
static hasMany = [names: String] }
I created also a Controller for the Class and added there:
static scaffold = Name
So far it is working but on in the view there are only the name of the String but i can not add any inputs to the list.
So therefore I'm looking for a solution, hope someone can help.
Thanks in advance!
You question is not very clear because of that what you want.
If i have understood you question here are my answers to you :
1.If you use scaffolding true grails will automatically generate pages and codes based on your domain configuration, if you need more inputs as you said add more domain variables like.i.e
class Name{
static hasMany = [names: String]
//to see more inputs add them here
String description
}
You have only one domain called Name and then what did you expect to see other more inputs you need other more member variables or property's..
If you are not satisfied with the component that grails created fro you can change it on .gsp file.
Great resource here http://goo.gl/f7XV8I
Let me know of further assistance...

wsdl objects are repeated when I add webservice reference

when I add webservice reference (not a service reference), I am getting same element with renamed added suffix as 1 as shown in the image. this causes an error when I try to debug. Inner exception says
Message=Types 'service.AddressType1' and 'service.AddressType' both use the XML type name, 'AddressType', from namespace 'xxx'. Use XML attributes to specify a unique XML name and/or namespace for the type.
I understand the error and I already saw some different threads here those tell me that I should specify different namespace but I don't have AddressType1 defined anywhere in my proxy classes. I have only AddressType. where from do I get that AddressType1 or others?
Anyone else got that error? thanks for your help.
Have you looked at this answer? Inheriting Existing .Net Class Serialization Error
This answer also discusses issues with hierarchical namespacing (seems you may be doing that), so that may be your main issue: Classes in different sub-namespaces all appear at top level in WSDL
It appears that you may need to specify the XmlTypeAttribute. Can you provide your code sample for review?
I was having inherited proxy classes which I generated using xsd2code tool. Problem was that this tool generated namespaces correctly for the parent xsd classes but when I check the class in the child which is shared/common by other parent classes, It appears that namespace field was empty as below. Therefore my service reference had same properties/classes more than one time with 1 suffix as shown in the question. I have just added same namespace for those child/inherited classes, It worked fine and no repeated properties. I hope that this helps to someone else having similar problem.
System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=True), _

Yii dynamic model id

So I'm working on some unit tests and relational fixtures.
I'm creating a model dynamically like:
$model = CActiveRecord::model('Post');
$post = $model->findByPk(1);
But after that I cannot for some reason get $post->id. I traced the problem to CActiveRecord class:
public function __get($name)
{
if(isset($this->_attributes[$name]))
return $this->_attributes[$name];
...
Where $name = "id". It says that $this->_attributes[$name] does not exist! As a matter of fact _attributes is empty.
My Post class does not define id (or any other properties) as a public property and I don't want to do so either. I just let the AR map it to table columns for me.
What am I missing?
Edit 1
My fixtures are regular Yii fixtures - nothing really special about them.
What differs is the way I load them really. I extended the CDbFixtureManager to be able to specify the order in which they should be loaded by overloading load() method. Only thing of interest that actually fails is that in the fixtures that have foreign keys I use the following:
'comment1' => array('post_id' => $this->getRecord('Post', 'post1')->id);
That's where it fails. getRecord returns the actual Post record (since I know the Post fixture has already been successfully loaded and exists in DB), but on the ->id part I get an exception about that attribute not existing.
If I go into Post model and add public $id; to it, then everything works! But I'm not sure if it's good practice to go about declaring all properties public like that.
If you look at this page carefully:
http://www.yiiframework.com/doc/guide/1.1/en/test.unit
you'll see that they use an array form for retrieving fixtures:
$this->posts['sample1']['id']
There is an alias defined in their fixture array for each record and fixture items aren't loaded as models really ...
Does that help? If not, it would be helpful to see your fixture file :-)
I think I found the root cause of this issue for me. While my FixtureManager was using the testdb DBConnection, the models still used the regular one.
For whatever reason, my debugger was giving me misleading errors like the one described in my original post.
Once I was able to set the DBConnection of all Models in the unit test the puzzle snapped into place and everything is now working smoothly!

urlize() in Doctrine_Inflector Class in Doctrine 2 / Symfony 2?

I was looking for a built-in method to urlize/slugify a string, instead of copying a strandard one found on google.
Thus I found this : http://sourcecookbook.com/en/recipes/59/call-the-slugify-urlize-function-from-doctrine , referencing to this Doctrine Class http://www.tig12.net/downloads/apidocs/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Doctrine_Inflector.class.html , with the method urlize() which is exactly what I'm looking for.
But, in my Doctrine Bundle from Symfony 2, in \vendor\doctrine\common\lib\Doctrine\Common\Util my Inflector class is pretty empty.
What happened to this urlize() method ? Do I have to recode it ?
There's https://github.com/Behat/Transliterator which includes the urlize function from Doctrine1
This is the part taken from Doctrine 1.2.3
Doctrine inflector has static methods for inflecting text
You could just composer require behat/transliterator
and have a HelperClass extending Behat\Transliterator.
And then be able to do: MyStringHelper::urlize("isn't that great?")
The file you are looking at (Doctrine\Common\Util\Inflector) is supposed to be used internally by Doctrine, to convert between table names (underscore separated), property names (camelCase), and class names (CamelCase).
What you are looking for can be achieved with the sluggable doctrine extension. You can ingtegrate it easily into a symfony2 application with stof/StofDoctrineExtensionsBundle.

Scala template accessing model object properties in Play 2.0

I have a simple question regarding accessing member variables of a model object.
I have the following model objects:
#Entity
public class Person extends Model{
#Id
public Long id;
public String name;
}
#Entity
public class Account extends Model{
#Id
public String email;
public String password;
#OneToOne
public Person person;
}
So far so good, Any given person can have a single account. The Account object is copied from the zentask example. After authentication I redirect to the index page which displays the user realname as stated in the Person.name member variable. The Account object is inserted in the page just as with the zentasks example like so:
Account.find.byId(Controller.request().username());
Now the following strange things happen in the template which i do not understand:
#account.person.name
results in a Null value inserted in the template while calling:
#account.person.getName() or #account.person.getName
results as expected with the correct name inserted from the person object.
#account.person
shows the .toString() of the person object, also correctly showing the name.
So to summarize: What is wrong with the code above? Why can I call the account.person value without any problems, but when I call account.person.name this does not work anymore
Thank you in advance!
Richard
This is because JPA uses Aspects to intercept getter usage and fill-in the missing data from objects that are lazy-loaded. I don't know what conventional thinking is, but I would not use public members ever with JPA for this reason, it will break the framework consistently.
If you really want to use public members, you'll have to mark relationships as eager fetching:
#OneToMany(fetch=FetchType.EAGER)
or explicitly fetch all of the object tree you'll need in your template (ugh).
In your case, the relationship, a OneToOne is defined on the other side of the relationship, if you define it on the Account side, it should fetch eager by default. I forget if you can define OneToOne on both entities, I think you can, but you might have to fiddle with it a bit.
Overall, don't use public members with JPA, it will break. Better yet, ditch JPA and use Anorm instead, it maps to the problem domain much more successfully than JPA. Issues like this consistently cause JPA implementations to take up twice as much implementation time as anyone seems able to predict.
I just stumbled upon an answer posted by Guillaume Bort, which explains things.
Read here:
https://groups.google.com/d/topic/play-framework/CNjH3w_yF6E/discussion
Hope this helps!
Because of lazy loading the values in the field only get loaded when you access them from the class itself.(something that, in normal circumstances would use a setter/getter
In order to load the values you ether have to write getters and setters.
Or you can create a methode that checks every value.
you can add the following methode to your Account Entity:
public void checker(){
if(email==null){}
if(password==null){}
if(person==null){}
}
this will load every value, but won't reduce performance