YouTube Icon

Interview Questions.

Top 100+ Xstream Interview Questions And Answers - May 24, 2020

fluid

Top 100+ Xstream Interview Questions And Answers

Question 1. Why Does Xstream Not Respect The Encoding In The Xml Declaration?

Answer :

XStream structure is based totally on IO Readers and Writers, while the XML declaration is the responsibility of XML parsers. All HierarchicalStreamDriver implementations appreciate the encoding due to the fact that version 1.Three, but best if you offer an InputStream. If XStream consumes a Reader you have to initialize the reader with the right encoding your self, since it is now the reader's project to perform the encoding and no XML parser can alternate the encoding of a Reader and any encoding definition inside the XML header may be overlooked.

Question 2. Why Does Xstream Not Write An Xml Declaration?

Answer :

XStream is designed to jot down XML snippets, so you can embed its output into an current movement or string. You can write the XML assertion your self into the Writer before the use of it to name XStream.ToXML(author).

File Maker Interview Questions

Question 3. Why Does Xstream Not Write Xml In Utf-eight?

Answer :

XStream does no person encoding by using itself, it relies at the configuration of the underlying XML writer. By default it uses its personal PrettyPrintWriter which writes into the default encoding of the present day locale. To write UTF-eight you have to offer a Writer with the best encoding your self.

Question four. Why Do Field Names Suddenly Have Double Underscores In The Generated Xml?

Answer :

XStream maps Java magnificence names and area names to XML tags or attributes. Unfortunately this mapping can't be 1:1, since a few characters used for identifiers in Java are invalid in XML names. Therefore XStream uses an XmlFriendlyNameCoder to update these characters with a replacement. By default this NameCoder uses an underscore as escape man or woman and has consequently to break out the underscore itself additionally. You might also offer a special configured instance of the XmlFriendlyNameCoder or a entire different implementation just like the NoNameCoder to prevent call coding in any respect. However it's far your responsibility then to make certain, that the ensuing names are legitimate for XML.

File Maker Tutorial

Question 5. Xstream Failed To Unmarshal My Given Xml And I Do Not Know Why?

Answer :

By default XStream is written for endurance i.E. It will examine the XML it is able to write. If you need to transform a given XML into an item graph, you should cross the other manner round. Use XStream to transfer your objects into XML. If the written XML matches your schema, XStream is also capable of examine it. This way is a good deal simpler, on the grounds that you may spot the variations in the XML an awful lot greater clean than to interpret the exceptions XStream will throw if it cannot match the XML into your gadgets.

J2EE Interview Questions

Question 6. Why Is My Element Not Written As Xml Attribute Although I Have Configured It?

Answer :

You can most effective write kinds as attributes which are represented as a single String value and are dealt with therefore by way of SingleValueConverter implementations. If your type is handled by means of a Converter implementation, the configuration of XStream to put in writing an attribute (the usage of XStream.UseAttributeFor() or @XStreamAsAttribute) is virtually overlooked.

Question 7. Why Are Whitespace Characters Wrong In My Attribute Values After Deserialization?

Answer :

This is a part of the XML specification and a required functionality for any XML parser called attribute fee normalization. It can not be motivated through XStream. A compliant XML parser will replace with the aid of default real tab, carriage go back and line feed characters with normal spaces. If you need to maintain those characters you'll ought to encode them with entities.

J2EE Tutorial Core Java Interview Questions

Question 8. Why Does Xstream Not Have Any Namespace Support?

Answer :

Not each XML parser supports namespaces and now not every XML parser that supports namespaces can be configured within XStream to apply the ones. Basically namespaces should be supported personally for the exclusive XML parsers and the simplest help for namespaces that has currently been applied in XStream is for the StAX paser. Therefore use and configure the StaxDriver of XStream to use namespaces.

Question 9. My Xml Contains Xpath Expressions In The References, But They Seem Not To Work?

Answer :

XStream generates best XPath compliant expressions. These have a very confined syntax and they may be the best ones that can be interpreted at deserialization again, seeing that XStream does not use an XPath interpreter. Therefore there's no assist for attribute selectors, certified detail access with axis names or features. For actual XPath guide you may ought to put into effect your very own MarshallingStrategy.

Android Interview Questions

Question 10. Does Xstream Support Entities?

Answer :

Entity aid is absolutely depending on the XML parser. XStream uses by default the Xpp3 parser that does not aid entities in any respect (like the kXML2 parser). Other parsers help entities, however they may have been grew to become off to keep away from XXE vulnerability. To allow the entities again, you need to overload the character technique of the HierarchicalStreamDriver implementation that generated the parser manufacturing unit.

Core Java Tutorial

Question 11. Why Are There Two Json Driver Implementations?

Answer :

As constantly, first for historic reasons! Main distinction is that the JettisonMappedXmlDriver is a thin wrapper around Jettison in combination with the StaxDriver, at the same time as the JsonHierarchicalStreamDriver uses an own extra flexible implementation, but can only be used to generate JSON, deserialization isn't always carried out.

JavaServer Faces (JSF) Interview Questions

Question 12. Which Versions Of Jettison Are Supported?

Answer :

Users of Java 5 or better can use Jettison 1.2, users of Java 1.Four.2 need to use Jettison 1.Zero.1. Jettison 1.1 nor Jettison 1.Three or higher is supported.

File Maker Interview Questions

Question 13. Why Is It Not Possible To Deserialize A Json String Starting With An Array?

Answer :

XStream's implementation to deserialize JSON is primarily based on Jettison and StAX. Jettison implements a XMLStreamReader of StaX and transforms the processed JSON certainly into XML first. However, if the JSON string begins with an array it isn't possible for Jettison to create a valid root detail, because it has no name.

Android Tutorial

Question 14. Xstream Fails To Unmarshal My Json String And I Do Not Know Why?

Answer :

Deserialization of JSON is presently completed by way of Jettison, that transforms the JSON string into a StAX movement. XStream itself does not anything recognize about the JSON layout right here. If your JSON string reaches a few form of complexity and you do now not understand how to layout your Java objects and configure XStream to suit the ones, you have to have a take a look at the intermediate XML this is processed by means of XStream in the end. This would possibly help to become aware of the complex spots. Also consider then marshalling your Java objects into XML first. You can use following code to generate the XML:

String json = ""string": "foo"";
HierarchicalStreamDriver motive force = new JettisonMappedXmlDriver();
StringReader reader = new StringReader(json);
HierarchicalStreamReader hsr = motive force.CreateReader(reader);
StringWriter author = new StringWriter();
new HierarchicalStreamCopier().Copy(hsr, new PrettyPrintWriter(writer));
author.Close();
System.Out.Println(creator.ToString());

Question 15. What Limitations Has Xstream's Json Support?

Answer :

JSON represents a totally easy facts model for clean statistics switch. Especially it has no equal for XML attributes. Those are written with a main "@" character, however this is not always viable without violating the syntax (e.G. For array sorts). Those may silently dropped (and makes it therefore hard to put in force deserialization). References are any other problem within the serialized item graph, on account that JSON has no opportunity to explicit this type of construct. You should therefore always set the NO_REFERENCES mode of XStream. Additionally you cannot use implicit collections, for the reason that houses in a JSON item must have particular names.

Java Swing Interview Questions

Question 16. Why Are My Long Values Incorrect In Javascript?

Answer :

JavaScript does no longer recognize about integer values. All numbers are represented with double precition floats the use of sixty four bits (IEEE 754). These types can't represent technically the entire value variety of 64-bit integers like Java's Long. With the JsonWriter you have got the opportunity considering that XStream 1.Four.Five to set IEEE_754_MODE to force any lengthy value that isn't representable as JavaScript variety to be written as string fee in JSON. With the Jettison-based totally JettisonMappedXmlDriver you could both set a different TypeConverter or force the default converter to jot down integer values out of the variety of 32-bit constantly as string placing the system property jettison.Mapped.Typeconverter.Enforce_32bit_integer to actual (now not available for Jettison 1.0.1 and Java 1.4).

JavaServer Faces (JSF) Tutorial

Question 17. Why Are There Invalid Characters In My Json Representation?

Answer :

The JSON spec requires any JSON string to be in UTF-8 encoding. However, XStream guarantees this only in case you offer an InputStream or an OutputStream. If you provide a Reader or Writer you need to make certain this requirement on your personal.

Javascript Objects Interview Questions

Question 18. Why Does Xstream Not Convert An Java.Beans.Eventhandler?

Answer :

Since XStream model 1.Four.7 it does no longer deal with an EventHandler mechanically. Such an instance can be used to initiate calls on arbitrary instances at deserialization time e.G. ProcessBuilder.Begin() You can check in a ReflectionConverter example explicitly for the EventHandler in case you want guide for such times.

J2EE Interview Questions

Question 19. Is Xstream Xxe Vulnerable (cve-2016-3674)?

Answer :

XStream does now not contain an personal XML parser, therefore it depends on the parser selected with the HierarchicalStreamDriver if the contemporary XStream instance is XXE inclined at deserialization time. However, XStream attempts to deactivate the processing of external entities through default. Status for the exceptional supported XML parsers.

Java Swing Tutorial

Question 20. How Does Xstream Compare To Java.Beans.Xmlencoder?

Answer :

XStream is designed for serializing gadgets the use of inner fields, while XMLEncoder is designed for serializing JavaBeans the use of public API techniques (usually within the form of getXXX(), setXXX(), addXXX() and removeXXX() techniques.

Javascript Advanced Interview Questions

Question 21. How Does Xstream Compare To Jaxb (java Api For Xml Binding)?

Answer :

JAXB is a Java binding device. It generates Java code from a schema and you are able to remodel from those training into XML matching the processed schema and again. Note, that you can not use your very own gadgets, you have to use what is generated.

Question 22. Is Xstream Thread Safe?

Answer :

Yes. Once the XStream instance has been created and configured, it is able to be shared throughout a couple of threads allowing gadgets to be serialized/deserialized concurrently (except you permit the automobile-detection to procedure annotations on-the-fly). Actually the introduction and initialization of XStream is pretty expensive, consequently it's far advocated to maintain the XStream example itself. If you really must depend on annotation processing on the fly, you'll need to use separate XStream instances for each thread - both by way of using each time a new instance or with the aid of a shared pool.

Javascript Objects Tutorial

Question 23. How Much Memory Does Xstream Consume?

Answer :

This can't be replied in fashionable, however following topics have effect at the memory:

    XML parser era in use: You must use a streaming parser like Xpp3 or StAX. DOM-primarily based parsers system the complete XML and create their document version in reminiscence earlier than the first converter of XStream is referred to as.
    Your item version: Is it vital to maintain the complete object graph in reminiscence at once? As opportunity you may use item streams or write custom converters which can load and save gadgets of your object version on the fly without adding them to the item graph physically. As example see the implementation of the XmlArrayList in aggregate with the FileStreamStrategy from XStream's endurance package deal to hold components of the item graph separate.
    References: By default XStream supports references to the identical item in an item graph. This implies that XStream keeps track of all serialized and deserialized items internally. These references are saved with WeakReferences, in order that the memory may be freed as quickly as nobody references those objects anymore.
    XML values: Any tag and attribute value this is converted into a Java String within the object graph will use by using default the equal String example unless it exceeds 38 characters (length of a UUID string illustration).
    XStream caches: To increase overall performance XStream caches quite lots like lessons, converters to use, aliasing, tag names. All those caches make utilization of WeakReferences or will exist only whilst marshalling one object graph resp. Unmarshalling one enter circulation.

JavaMail API Interview Questions

Question 24. Can The Performance Of Xstream Be Increased?

Answer :

XStream is a generalizing library, it inspects and handles your sorts at the fly. Therefore it will normally be slower than a piece of optimized Java code generated out of a schema. However, it is viable to increase the overall performance besides:

    Write custom converters for the ones of your sorts that occur very regularly for your XML.
    Keep a configured XStream example for a couple of usage. Creation and initialization is pretty luxurious compared to the overhead of XStream whilst calling marshall or unmarshal.
    Use Xpp3 or StAX parsers.

Note, you should by no means try to optimize code for overall performance really due to the fact you trust that you have detected a bottle neck. Always use proper gear like a profiler to confirm in which your hotspots are and whether or not your optimization became without a doubt a success or no longer.

Core Java Interview Questions

Question 25. Is Xstream A Data Binding Tool?

Answer :

No. It is a serialization tool.

Javascript Advanced Tutorial

Question 26. Can Xstream Generate Classes From Xsd?

Answer :

No. For this kind of paintings information binding tools which includes JAXB or XMLBeans are suitable.

Java collections framework Interview Questions

Question 27. Why Is There No Saxreader?

Answer :

XStream works on a movement-based parser model, whilst SAX is occasion-based totally. The circulation based model implies, that the caller consumes the person tokens from the XML parser on demand, while in an occasion-based version the parser controls the utility glide on its personal and could use callbacks to support patron processing. The special architecture makes it consequently impossible for XStream to apply an event-pushed XML parser.




CFG