<commit_before>package org.opentosca.yamlconverter.main;

import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

public class XmlAnyLaxTest {

	// @formatter:off
	private static final String xml = "<message to=\"<EMAIL>\" from=\"<EMAIL>\">" +
			"<customer>" +
			"<name><NAME></name>" +
			"<address>" +
			"<street>123 A Street</street>" +
			"<city>Any Town</city>" +
			"</address>" +
			"</customer>" +
			"</message>";
	// @formatter:on

	public static void main(String[] args) throws Exception {
		final JAXBContext jc = JAXBContext
				.newInstance(Message.class, Customer.class, Address.class, GenericProperties.class, HashMap.class);

		final Unmarshaller unmarshaller = jc.createUnmarshaller();
		final Message message = (Message) unmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes()));

		// TODO Does not work!
		final GenericProperties props = new GenericProperties();
		props.properties = new HashMap<String, String>();
		props.properties.put("lol", "yeah");

		message.body = props;

		final Marshaller marshaller = jc.createMarshaller();
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		marshaller.marshal(message, System.out);
	}

	@XmlRootElement
	@XmlAccessorType(XmlAccessType.FIELD)
	static class GenericProperties {

		public Map<String, String> properties;

	}

	@XmlRootElement
	@XmlAccessorType(XmlAccessType.FIELD)
	static class Message {

		@XmlAttribute
		private String to;
<commit_msg>Xml Lax Test added<commit_after>package org.opentosca.yamlconverter.main;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.namespace.QName;

public class XmlAnyLaxTest {

	// @formatter:off
	private static final String xml =
			"<message to=\"<EMAIL>\" from=\"<EMAIL>\">" +
					"<customer>" +
					"<name><NAME></name>" +
					"<address>" +
					"<street>123 A Street</street>" +
					"<city>Any Town</city>" +
					"</address>" +
					"</customer>" +
					"</message>";
	// @formatter:on

	public static void main(String[] args) throws Exception {
		final JAXBContext jc = JAXBContext
				.newInstance(Message.class, Customer.class, Address.class, GenericProperties.class, HashMap.class);

		final Unmarshaller unmarshaller = jc.createUnmarshaller();
		final Message message = (Message) unmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes()));

		final Map<String, String> map = new LinkedHashMap<String, String>();
		map.put("key1", "value1");
		map.put("key2", "value2");
		final GenericProperties props = new GenericProperties(map);

		message.body = props;

		final Marshaller marshaller = jc.createMarshaller();
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		marshaller.marshal(message, System.out);
	}

	@XmlRootElement(name = "Properties")
	static class GenericProperties {
		@XmlAnyElement
		public List<JAXBElement<String>> entries = new ArrayList<JAXBElement<String>>();

		public GenericProperties() { // JAXB required
		}

		public GenericProperties(Map<String, String> map) {
			for (final Map.Entry<String, String> entry : map.entrySet()) {
				this.entries.add(new JAXBElement<String>(new QName(entry.getKey()), String.class, entry.getValue()));
			}
		}
	}

	@XmlRootElement
	@XmlAccessorType(XmlAccessType.FIELD)
	static class Message {

		@XmlAttribute
		private String to;

{'fraction_non_alphanumeric': 0.1326775431861804, 'fraction_numerical': 0.0023992322456813818, 'mean_word_length': 4.989942528735632, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1379094', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1304, 'n_words': 269}