Problem of setting up a lifetime of cookie

Hello, all!

I have a problem. I create cookie and try to put in it xml (generated by jaxb) or serialized class casted to string. Any case, lifetime of cookie is “browser session close”, although I set it up for one year. If I put to cookie value of any attribute of sending class or any String, a lifetime of cookie is exactly what I want. There is my source:


works wrong:
try {			
	        JAXBContext context = JAXBContext.newInstance(TEModel.class);
	        Marshaller m = context.createMarshaller();
	        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
	        m.setProperty(Marshaller.JAXB_ENCODING, "Windows-1251");	        	               

	        outputStream = new ByteArrayOutputStream();
	        m.marshal(teModel, outputStream);
	        
	        System.out.println(outputStream.toString());
	        
	        String str = outputStream.toString();
	        Cookie cookie = new Cookie("asptem", str);
		cookie.setMaxAge(3600*24*365); // One year
		response.addCookie(cookie);
    	} catch (JAXBException ex) {
    		System.err.println(ex.getMessage());
    	}

works correctly :
try {			
	        JAXBContext context = JAXBContext.newInstance(TEModel.class);
	        Marshaller m = context.createMarshaller();
	        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
	        m.setProperty(Marshaller.JAXB_ENCODING, "Windows-1251");	        	               

	        outputStream = new ByteArrayOutputStream();
	        m.marshal(teModel, outputStream);
	        
	        System.out.println(outputStream.toString());
	        
	        String str = teModel.getStyle(); //return value of String
	        Cookie cookie = new Cookie("asptem", str);
		cookie.setMaxAge(3600*24*365); // One year
		response.addCookie(cookie);
    	} catch (JAXBException ex) {
    		System.err.println(ex.getMessage());
    	}

Please tell me, where I’m wrong?